Skip to content

Commit

Permalink
FEAT: Add printer Tool model object
Browse files Browse the repository at this point in the history
  • Loading branch information
josefdolezal committed May 9, 2017
1 parent d5839c2 commit 97ec18d
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
12 changes: 12 additions & 0 deletions OctoPhone.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
D20E419F1E88626300CE99BA /* LogDetailCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20E419E1E88626300CE99BA /* LogDetailCoordinator.swift */; };
D20E41A11E88633F00CE99BA /* LogDetailViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20E41A01E88633F00CE99BA /* LogDetailViewModel.swift */; };
D20E41A31E88747900CE99BA /* LogDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D20E41A21E88747900CE99BA /* LogDetailViewController.swift */; };
D210B8761EC1EFC700363E3F /* Tool.swift in Sources */ = {isa = PBXBuildFile; fileRef = D210B8751EC1EFC700363E3F /* Tool.swift */; };
D210B8781EC1F13C00363E3F /* Tool+JSONAble.swift in Sources */ = {isa = PBXBuildFile; fileRef = D210B8771EC1F13C00363E3F /* Tool+JSONAble.swift */; };
D210B87A1EC1F1D200363E3F /* ToolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D210B8791EC1F1D200363E3F /* ToolTests.swift */; };
D2128BB91EAD3A09001FAB6F /* SDCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2128BB81EAD3A09001FAB6F /* SDCardView.swift */; };
D2128BBB1EAD3A79001FAB6F /* RoundedButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2128BBA1EAD3A79001FAB6F /* RoundedButton.swift */; };
D2132B571E98DF7500FA3ACD /* Disposable+CompositeDisposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2132B561E98DF7500FA3ACD /* Disposable+CompositeDisposable.swift */; };
Expand Down Expand Up @@ -272,6 +275,9 @@
D20E419E1E88626300CE99BA /* LogDetailCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogDetailCoordinator.swift; sourceTree = "<group>"; };
D20E41A01E88633F00CE99BA /* LogDetailViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = LogDetailViewModel.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
D20E41A21E88747900CE99BA /* LogDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogDetailViewController.swift; sourceTree = "<group>"; };
D210B8751EC1EFC700363E3F /* Tool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tool.swift; sourceTree = "<group>"; };
D210B8771EC1F13C00363E3F /* Tool+JSONAble.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Tool+JSONAble.swift"; sourceTree = "<group>"; };
D210B8791EC1F1D200363E3F /* ToolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToolTests.swift; sourceTree = "<group>"; };
D2128BB81EAD3A09001FAB6F /* SDCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SDCardView.swift; sourceTree = "<group>"; };
D2128BBA1EAD3A79001FAB6F /* RoundedButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoundedButton.swift; sourceTree = "<group>"; };
D2132B561E98DF7500FA3ACD /* Disposable+CompositeDisposable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Disposable+CompositeDisposable.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -589,6 +595,7 @@
D22102C01EAD0F56005517EB /* SDCard.swift */,
D22444171EB8902F0026CE68 /* Bed.swift */,
D224441B1EB891B90026CE68 /* PrinterState.swift */,
D210B8751EC1EFC700363E3F /* Tool.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -664,6 +671,7 @@
D22102C41EAD14D6005517EB /* SDCard+JSONAble.swift */,
D224441F1EB89E240026CE68 /* Bed+JSONAble.swift */,
D22444241EB8B2C90026CE68 /* PrinterState+JSONAble.swift */,
D210B8771EC1F13C00363E3F /* Tool+JSONAble.swift */,
);
path = "Model Mapping";
sourceTree = "<group>";
Expand Down Expand Up @@ -692,6 +700,7 @@
D22102C61EAD15A0005517EB /* SDCardTests.swift */,
D22444191EB8915B0026CE68 /* BedTests.swift */,
D22444281EB8B3C70026CE68 /* PrinterStateTests.swift */,
D210B8791EC1F1D200363E3F /* ToolTests.swift */,
);
name = "Model Mapping";
sourceTree = "<group>";
Expand Down Expand Up @@ -1572,8 +1581,10 @@
D22444201EB89E240026CE68 /* Bed+JSONAble.swift in Sources */,
D21F3F8B1E6493CA00351761 /* PrinterListViewModel.swift in Sources */,
D28EC5391E09E6740089C027 /* SettingsViewController.swift in Sources */,
D210B8761EC1EFC700363E3F /* Tool.swift in Sources */,
D2688D851E91154000290421 /* SlicingProfileCoordinator.swift in Sources */,
D23F0CDD1E919FB600A70BC9 /* PrinterProfile.swift in Sources */,
D210B8781EC1F13C00363E3F /* Tool+JSONAble.swift in Sources */,
D2C8AF331E92E3E800DC7914 /* PrintProfileViewController.swift in Sources */,
D22444321EB922B30026CE68 /* ConnectPrinterViewController.swift in Sources */,
D2F765961E788C3000A5BC11 /* CommandCellViewModel.swift in Sources */,
Expand Down Expand Up @@ -1622,6 +1633,7 @@
D2FEDE721E6ED36200184CEC /* PrinterListViewModelTests.swift in Sources */,
D2C38CC51E7D49A200D06698 /* LogsViewModelTests.swift in Sources */,
D2FEDE781E6EEDDB00184CEC /* SignalProducer+JSONAbleTests.swift in Sources */,
D210B87A1EC1F1D200363E3F /* ToolTests.swift in Sources */,
D22102C71EAD15A0005517EB /* SDCardTests.swift in Sources */,
D2C38CD11E7FF87D00D06698 /* LogCellViewModelTests.swift in Sources */,
D224441A1EB8915B0026CE68 /* BedTests.swift in Sources */,
Expand Down
37 changes: 37 additions & 0 deletions OctoPhone/Model/Tool.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Tool.swift
// OctoPhone
//
// Created by Josef Dolezal on 09/05/2017.
// Copyright © 2017 Josef Dolezal. All rights reserved.
//

import Foundation
import RealmSwift

/// Print tool object
final class Tool {

// MARK: - Stored properties

/// Actual temperature of hotend
var actualTemperature = 0.0

/// Offset temperature
var offsetTemperature = 0.0

/// Target temperature
var targetTemperature = 0.0

// MARK: - Computed properties

// MARK: - Public API

init(actual: Double, offset: Double, target: Double) {
self.actualTemperature = actual
self.offsetTemperature = offset
self.targetTemperature = target
}

// MARK: - Realm API
}
24 changes: 24 additions & 0 deletions OctoPhone/Networking/Model Mapping/Tool+JSONAble.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Tool+JSONAble.swift
// OctoPhone
//
// Created by Josef Dolezal on 09/05/2017.
// Copyright © 2017 Josef Dolezal. All rights reserved.
//

import Foundation

// MARK: - JSONAble
extension Tool: JSONAble {
static func fromJSON(json: [String : Any]) throws -> Tool {
guard
let actual = json["actual"] as? Double,
let offset = json["offset"] as? Double,
let target = json["target"] as? Double
else {
throw JSONAbleError.errorMappingJSONToObject(json: json)
}

return Tool(actual: actual, offset: offset, target: target)
}
}
50 changes: 50 additions & 0 deletions OctoPhoneTests/Networking/Model Mapping/ToolTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// ToolTests.swift
// OctoPhone
//
// Created by Josef Dolezal on 09/05/2017.
// Copyright © 2017 Josef Dolezal. All rights reserved.
//

import Nimble
import Quick
@testable import OctoPhone

class ToolTests: QuickSpec {
override func spec() {
describe("Tool") {
describe("converts from JSON") {
var data: [String: Any]!

afterEach {
data = nil
}

context("valid JSON") {
beforeEach {
data = ["target": 200.0, "offset": 5.0, "actual": 99.1]
}

it("converts") {
expect { try Tool.fromJSON(json: data) }.notTo(throwError())
if let subject = try? Tool.fromJSON(json: data) {
expect(subject.actualTemperature) == 99.1
expect(subject.offsetTemperature) == 5.0
expect(subject.targetTemperature) == 200.0
}
}
}

context("invalid JSON") {
beforeEach {
data = [:]
}

it("throws an error") {
expect { try Tool.fromJSON(json: data) }.to(throwError())
}
}
}
}
}
}

0 comments on commit 97ec18d

Please sign in to comment.