pm25 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc572dc7b0470481bf49d0af5120410fbcbdd331
4
- data.tar.gz: cf76f74f9da3fb29c51d2bd74aa68a9bf7e08a0b
3
+ metadata.gz: 1d1ff063f038d524ba9fac5b0c1f6ee992a8c487
4
+ data.tar.gz: 2b375b5bae4a640267481a083c7d5829727bc22d
5
5
  SHA512:
6
- metadata.gz: ef22e986f06fbece1d130fcb98ee0dcada03544fb621e8fa39e8df1d07b6512c9afc0cb6143bbf28ead2d3ce43896160205ede70aa6081fdc7768fc870197960
7
- data.tar.gz: 048130ad1ac1f10a20dca49436173e32fc6ff9fef3dd6eaec442a72bc6bfdfc187551d0cf27f12af452b9eb9e960076a5fb8de4383993dfd885886905457ce60
6
+ metadata.gz: 0f32857cef830efd1c32e57d1b3ab5c3eb85860a44a09507877d8a678c64c611f2862952e3ecf8e798f05e98510f8ffc55f33cad0fdd356e85639c435b2fe8af
7
+ data.tar.gz: 9207780cc22623564bf281642ed02ba06926bbb61de26221a1853719435c58ffdf07110ea3ff16d323ddfdd161b9f0ea8693498fb0220a403c3605a581a5fe27
data/README.md CHANGED
@@ -70,7 +70,7 @@ PM25::Beijing.all
70
70
  # - 'Desc': string
71
71
  # - 'ReadingDateTime': datetime
72
72
 
73
- PM25::Beijing.last
73
+ PM25::Beijing.last # or PM25::Beijing.latest
74
74
  # => return a hash with the latest data, all value been parsed:
75
75
  # {"Conc"=>125.0,
76
76
  # "AQI"=>187,
@@ -14,11 +14,14 @@ module PM25
14
14
  end
15
15
 
16
16
  def self.all
17
- get.select{|x| x.key? 'AQI'}.map(&method(:slice)).map(&method(:parse))
17
+ get.select{|x| x.key? 'AQI'}.map(&method(:clean_up))
18
18
  end
19
19
 
20
20
  def self.last
21
- parse slice(get.find{|x| x.key? 'AQI'})
21
+ clean_up(get.find{|x| x.key? 'AQI'})
22
+ end
23
+ class << self
24
+ alias_method :latest, :last
22
25
  end
23
26
 
24
27
  def self.uri
@@ -43,6 +46,10 @@ module PM25
43
46
  parsed_data['ReadingDateTime'] = DateTime.strptime(data['ReadingDateTime'], '%m/%d/%Y %I:%M:%S %p')
44
47
  parsed_data
45
48
  end
49
+
50
+ def self.clean_up(data)
51
+ parse slice(data)
52
+ end
46
53
  end
47
54
  end
48
55
 
@@ -1,3 +1,3 @@
1
1
  module PM25
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -34,6 +34,21 @@ describe PM25::Base do
34
34
  hash_b['ReadingDateTime'].should be_a(DateTime)
35
35
  hash_b['ReadingDateTime'].should eq(DateTime.strptime(hash_a['ReadingDateTime'], '%m/%d/%Y %I:%M:%S %p'))
36
36
  end
37
+
38
+ it 'should slice and parse a hash when call `clean_up` method' do
39
+ hash_b = _class.clean_up(hash_a)
40
+ hash_b.should be_a(Hash)
41
+ _class::ATTRS.all?{|x| hash_b.key?(x)}.should eq(true)
42
+ hash_b.key?('a').should eq(false)
43
+ hash_b.key?('b').should eq(false)
44
+
45
+ hash_b['Conc'].should be_a(Float)
46
+ hash_b['Conc'].should eq(125.0)
47
+ hash_b['AQI'].should be_a(Integer)
48
+ hash_b['AQI'].should eq(187)
49
+ hash_b['ReadingDateTime'].should be_a(DateTime)
50
+ hash_b['ReadingDateTime'].should eq(DateTime.strptime(hash_a['ReadingDateTime'], '%m/%d/%Y %I:%M:%S %p'))
51
+ end
37
52
  end
38
53
 
39
54
  context 'Class attributes and constant' do
@@ -29,13 +29,22 @@ shared_examples "city common examples" do |city_class, city_id|
29
29
  end
30
30
 
31
31
  it 'should return the latest parsed data clice by ATTRS from remote when call `last` method' do
32
+ city_class.stub(:get) {
33
+ [{"title"=>"06/28/2013 11:00:00 AM", "description"=>"06-28-2013 11:00; PM2.5; 6.0; 25; Good (at 24-hour exposure at this level)", "Param"=>"PM2.5", "Conc"=>"6.0", "Desc"=>"Good (at 24-hour exposure at this level)", "ReadingDateTime"=>"06/28/2013 11:00:00 AM"},
34
+ {"title"=>"06/28/2013 10:00:00 AM", "description"=>"06-28-2013 10:00; PM2.5; 12.0; 50; Good (at 24-hour exposure at this level)", "Param"=>"PM2.5", "Conc"=>"12.0", "AQI"=>"50", "Desc"=>"Good (at 24-hour exposure at this level)", "ReadingDateTime"=>"06/28/2013 10:00:00 AM"}
35
+ ]
36
+ }
32
37
  data = city_class.last
33
38
  data.should be_a(Hash)
34
39
  data.keys.should eq(city_class::ATTRS)
35
40
  data['Conc'].should be_a(Float)
41
+ data['Conc'].should eq(12.0)
36
42
  data['AQI'].should be_a(Integer)
43
+ data['AQI'].should eq(50)
37
44
  data['Desc'].should be_a(String)
45
+ data['Desc'].should eq('Good (at 24-hour exposure at this level)')
38
46
  data['ReadingDateTime'].should be_a(DateTime)
47
+ data['ReadingDateTime'].should eq(DateTime.strptime('06/28/2013 10:00:00 AM', '%m/%d/%Y %I:%M:%S %p'))
39
48
  end
40
49
 
41
50
  it 'should return URI::HTTP object own context when call `uri` method' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pm25
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xuhao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-21 00:00:00.000000000 Z
11
+ date: 2013-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler