Floppy-currentcost 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,43 +13,56 @@ module CurrentCost
13
13
  doc = REXML::Document.new(xml)
14
14
  # Create reading object
15
15
  r = Reading.new
16
+ # Check version
17
+ r.software_version = REXML::XPath.first(doc, "/msg/src/sver").text rescue nil
18
+ if r.software_version.nil?
19
+ r.software_version = REXML::XPath.first(doc, "/msg/src").text
20
+ end
16
21
  # Extract basic data
17
- r.days_since_birth = REXML::XPath.first(doc, "/msg/date/dsb").text.to_i
18
- r.hour = REXML::XPath.first(doc, "/msg/date/hr").text.to_i
19
- r.minute = REXML::XPath.first(doc, "/msg/date/min").text.to_i
20
- r.second = REXML::XPath.first(doc, "/msg/date/sec").text.to_i
21
- r.name = REXML::XPath.first(doc, "/msg/src/name").text
22
- r.id = REXML::XPath.first(doc, "/msg/src/id").text
23
- r.type = REXML::XPath.first(doc, "/msg/src/type").text
24
- r.software_version = REXML::XPath.first(doc, "/msg/src/sver").text
25
- r.temperature = REXML::XPath.first(doc, "/msg/tmpr").text.to_f
22
+ if r.software_version.include? "CC128"
23
+ r.days_since_birth = REXML::XPath.first(doc, "/msg/dsb").text.to_i
24
+ r.hour, r.minute, r.second = REXML::XPath.first(doc, "/msg/time").text.split(':').map{|x| x.to_i}
25
+ r.id = REXML::XPath.first(doc, "/msg/id").text
26
+ r.type = REXML::XPath.first(doc, "/msg/type").text
27
+ r.temperature = REXML::XPath.first(doc, "/msg/tmpr").text.to_f
28
+ else
29
+ r.days_since_birth = REXML::XPath.first(doc, "/msg/date/dsb").text.to_i
30
+ r.hour = REXML::XPath.first(doc, "/msg/date/hr").text.to_i
31
+ r.minute = REXML::XPath.first(doc, "/msg/date/min").text.to_i
32
+ r.second = REXML::XPath.first(doc, "/msg/date/sec").text.to_i
33
+ r.name = REXML::XPath.first(doc, "/msg/src/name").text
34
+ r.id = REXML::XPath.first(doc, "/msg/src/id").text
35
+ r.type = REXML::XPath.first(doc, "/msg/src/type").text
36
+ r.temperature = REXML::XPath.first(doc, "/msg/tmpr").text.to_f
37
+ # Extract history data
38
+ if REXML::XPath.first(doc, "/msg/hist")
39
+ r.history = {}
40
+ r.history[:hours] = []
41
+ REXML::XPath.each(doc, "/msg/hist/hrs/*") do |node|
42
+ r.history[:hours][node.name.slice(1,2).to_i] = node.text.to_f
43
+ end
44
+ r.history[:days] = []
45
+ REXML::XPath.each(doc, "/msg/hist/days/*") do |node|
46
+ r.history[:days][node.name.slice(1,2).to_i] = node.text.to_i
47
+ end
48
+ r.history[:months] = []
49
+ REXML::XPath.each(doc, "/msg/hist/mths/*") do |node|
50
+ r.history[:months][node.name.slice(1,2).to_i] = node.text.to_i
51
+ end
52
+ r.history[:years] = []
53
+ REXML::XPath.each(doc, "/msg/hist/yrs/*") do |node|
54
+ r.history[:years][node.name.slice(1,2).to_i] = node.text.to_i
55
+ end
56
+ end
57
+ end
58
+ # Common information
26
59
  r.channels = []
27
60
  REXML::XPath.each(doc, "/msg/*/watts") do |node|
28
61
  r.channels << { :watts => node.text.to_i }
29
62
  end
30
- # Extract history data
31
- if REXML::XPath.first(doc, "/msg/hist")
32
- r.history = {}
33
- r.history[:hours] = []
34
- REXML::XPath.each(doc, "/msg/hist/hrs/*") do |node|
35
- r.history[:hours][node.name.slice(1,2).to_i] = node.text.to_f
36
- end
37
- r.history[:days] = []
38
- REXML::XPath.each(doc, "/msg/hist/days/*") do |node|
39
- r.history[:days][node.name.slice(1,2).to_i] = node.text.to_i
40
- end
41
- r.history[:months] = []
42
- REXML::XPath.each(doc, "/msg/hist/mths/*") do |node|
43
- r.history[:months][node.name.slice(1,2).to_i] = node.text.to_i
44
- end
45
- r.history[:years] = []
46
- REXML::XPath.each(doc, "/msg/hist/yrs/*") do |node|
47
- r.history[:years][node.name.slice(1,2).to_i] = node.text.to_i
48
- end
49
- end
50
63
  # Done
51
64
  return r
52
- rescue
65
+ rescue
53
66
  raise CurrentCost::ParseError.new("Couldn't parse XML data.")
54
67
  end
55
68
 
@@ -2,8 +2,8 @@ module CurrentCost
2
2
 
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
- MINOR = 1
6
- TINY = 2
5
+ MINOR = 3
6
+ TINY = 0
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Floppy-currentcost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-28 00:00:00 -07:00
12
+ date: 2009-02-17 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: Floppy-rb232
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements: