pm25 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d4e9cf8a047d64cfb512a1b1e34b74c757bca21
4
- data.tar.gz: 8b3d11aecaec6fd94ee6a3e13f4b8b5b6e77e8c4
3
+ metadata.gz: b2ff8a87d9a989a23ccbac7f456fe7991fde761a
4
+ data.tar.gz: 46a4b233864cbeb0f1288dab7d1cb8a246c2c20e
5
5
  SHA512:
6
- metadata.gz: f4e2a47f1af8ff811132040b5e92365df8773906129e5af96b127f8352d9e56d24eb0b62787afbeb578c9590649f5711a5452cd78637eab2a42ca1756e49b647
7
- data.tar.gz: 34a8c136097602f86e226a1b88eea5d1fc21c4866d2e39bbcdfe0f959f8e6f27a0365e542a3c37badaf994eda0c61f86c75f59a24dac211b900c7bae8f3648a5
6
+ metadata.gz: bef052ab41a4a9c59235066d64cee2e9ce6e4704e90c5012fa86d72cf9b806e2d195d677c920642670f2868d52ae497737425e7556ec42ced8164418b564176a
7
+ data.tar.gz: 74bdaec6a5989ca25f2dbb7aade5a55e06fbc730e3347029e604367241077fa8a9f6aec2a9ae7cd01ffa1ff90069f5cbe40adbce9c0044814c7283b032eb8e23
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
 
32
32
  ```ruby
33
33
  # Beijing
34
- PM25::Beijing.get
34
+ PM25::Beijing.get
35
35
  # => return an array include current and history data:
36
36
  # [{"title"=>"06/04/2013 6:00:00 PM",
37
37
  # "link"=>"http://www.stateair.net/web/post/1/1.html",
@@ -45,14 +45,31 @@ PM25::Beijing.get
45
45
  # {"title"=>"06/04/2013 5:00:00 PM",
46
46
  # ......
47
47
 
48
+ PM25::Beijing.latest
49
+ # => return a hash with the latest data, all value was parsed:
50
+ # {"Conc"=>162.0,
51
+ # "AQI"=>212,
52
+ # "Desc"=>"Very Unhealthy (at 24-hour exposure at this level)",
53
+ # "ReadingDateTime"=>Sat, 06 Jul 2013 17:00:00 +0000}
54
+ # "ReadingDateTime"=>"06/07/2013 5:00:00 PM"}
55
+ #
56
+ # column types:
57
+ # - 'Conc': float
58
+ # - 'AQI': integer
59
+ # - 'Desc': string
60
+ # - 'ReadingDateTime': datetime
61
+
48
62
  # Shanghai
49
63
  PM25::Shanghai.get
64
+ PM25::Shanghai.latest
50
65
 
51
66
  # Chengdu
52
67
  PM25::Chengdu.get
68
+ PM25::Chengdu.latest
53
69
 
54
70
  # Guangzhou
55
71
  PM25::Guangzhou.get
72
+ PM25::Guangzhou.latest
56
73
 
57
74
  # Shenyang
58
75
  PM25::Shenyang.get
data/lib/pm25/base.rb CHANGED
@@ -4,7 +4,7 @@ require 'active_support/core_ext/hash/conversions'
4
4
  module PM25
5
5
  class Base
6
6
  include HTTParty
7
-
7
+ ATTRS = %w(Conc AQI Desc ReadingDateTime)
8
8
  class_attribute :base_uri, :city_id
9
9
  self.base_uri = URI::HTTP.build({host: 'www.stateair.net'})
10
10
 
@@ -12,6 +12,10 @@ module PM25
12
12
  Hash.from_xml(HTTParty.get(url).body)['rss']['channel']['item']
13
13
  end
14
14
 
15
+ def self.latest
16
+ parse(get.find{|x| x.key? 'AQI'}.slice(*ATTRS))
17
+ end
18
+
15
19
  def self.uri
16
20
  raise NotImplementedError, "Please set value for 'city_id' class attributes in '#{self.name}' class." unless self.city_id
17
21
  self.base_uri.path = "/web/rss/1/#{self.city_id.to_s}.xml"
@@ -21,6 +25,13 @@ module PM25
21
25
  def self.url
22
26
  uri.to_s
23
27
  end
28
+
29
+ def self.parse(data)
30
+ data['Conc'] = data['Conc'].to_f
31
+ data['AQI'] = data['AQI'].to_i
32
+ data['ReadingDateTime'] = DateTime.parse(data['ReadingDateTime'])
33
+ data
34
+ end
24
35
  end
25
36
  end
26
37
 
data/lib/pm25/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pm25
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
4
+ version: 0.0.2
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-04 00:00:00.000000000 Z
11
+ date: 2013-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler