pm25 0.0.3 → 0.0.4

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: 9ab93196de911f044eddb954a668c5d22d4a91db
4
- data.tar.gz: e95313819d4b17c7c1000fed8b5edd53803541fd
3
+ metadata.gz: dc572dc7b0470481bf49d0af5120410fbcbdd331
4
+ data.tar.gz: cf76f74f9da3fb29c51d2bd74aa68a9bf7e08a0b
5
5
  SHA512:
6
- metadata.gz: da1aa51442b263b4f2bb552da55317207598817d0ba3386d3a5beec3122eb377960f0477f581bd9f34b843f2aefacb653beaa0a34e2b8ff4e5a87b83445cfceb
7
- data.tar.gz: 4baf7cf46b287ce60cd211b78f3187f59156e2b710443b55ecdf94d1fd1ba51290925ff921d941b8455848be96ab2fd10b56b59a8e7016fa6c8796e28d476c1e
6
+ metadata.gz: ef22e986f06fbece1d130fcb98ee0dcada03544fb621e8fa39e8df1d07b6512c9afc0cb6143bbf28ead2d3ce43896160205ede70aa6081fdc7768fc870197960
7
+ data.tar.gz: 048130ad1ac1f10a20dca49436173e32fc6ff9fef3dd6eaec442a72bc6bfdfc187551d0cf27f12af452b9eb9e960076a5fb8de4383993dfd885886905457ce60
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .versions.conf
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in pm25.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rake', group: :test
6
+ gem 'rake', group: :test
7
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # PM25
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/pm25.png)](http://badge.fury.io/rb/pm25)
3
4
  [![Build Status](https://www.travis-ci.org/ekohe/pm25.png?branch=master)](https://www.travis-ci.org/ekohe/pm25)
4
5
  [![Code Climate](https://codeclimate.com/github/ekohe/pm25.png)](https://codeclimate.com/github/ekohe/pm25)
6
+ [![Dependency Status](https://gemnasium.com/ekohe/pm25.png)](https://gemnasium.com/ekohe/pm25)
7
+ [![Coverage Status](https://coveralls.io/repos/ekohe/pm25/badge.png)](https://coveralls.io/r/ekohe/pm25)
5
8
 
6
- PM2.5 and ozone readings Data From U.S. Consulate.
7
-
8
- Include below cities of China:
9
+ China PM2.5 and ozone readings Data From U.S. Consulate. Include below cities of China:
9
10
 
10
11
  - Beijing
11
12
  - Shanghai
@@ -13,6 +14,8 @@ Include below cities of China:
13
14
  - Guangzhou
14
15
  - Shenyang
15
16
 
17
+ Another gem about Air Quality Index of China available here [ChinaAqi][china_aqi], all monitoring stations in most cities of China are available, most AQI data are available, all the data is form China's official sector. Check it out!
18
+
16
19
  ## Installation
17
20
 
18
21
  Add this line to your application's Gemfile:
@@ -103,3 +106,5 @@ PM25::Shenyang.last
103
106
  3. Commit your changes (`git commit -am 'Add some feature'`)
104
107
  4. Push to the branch (`git push origin my-new-feature`)
105
108
  5. Create new Pull Request
109
+
110
+ [china_aqi]: https://github.com/Xuhao/china_aqi
data/lib/pm25/base.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'httparty'
2
2
  require 'active_support/core_ext/class/attribute'
3
3
  require 'active_support/core_ext/hash/conversions'
4
+ require 'active_support/core_ext/hash/slice'
4
5
  module PM25
5
6
  class Base
6
7
  include HTTParty
@@ -35,10 +36,12 @@ module PM25
35
36
  end
36
37
 
37
38
  def self.parse(data)
38
- data['Conc'] = data['Conc'].to_f
39
- data['AQI'] = data['AQI'].to_i
40
- data['ReadingDateTime'] = DateTime.strptime(data['ReadingDateTime'], '%m/%d/%Y %I:%M:%S %p')
41
- data
39
+ parsed_data = {}
40
+ parsed_data['Conc'] = data['Conc'].to_f
41
+ parsed_data['AQI'] = data['AQI'].to_i
42
+ parsed_data['Desc'] = data['Desc'].to_s
43
+ parsed_data['ReadingDateTime'] = DateTime.strptime(data['ReadingDateTime'], '%m/%d/%Y %I:%M:%S %p')
44
+ parsed_data
42
45
  end
43
46
  end
44
47
  end
data/lib/pm25/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Pm25
2
- VERSION = "0.0.3"
1
+ module PM25
2
+ VERSION = "0.0.4"
3
3
  end
data/pm25.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'pm25/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "pm25"
8
- spec.version = Pm25::VERSION
8
+ spec.version = PM25::VERSION
9
9
  spec.authors = ["Xuhao"]
10
10
  spec.email = ["xuhao@rubyfans.com"]
11
11
  spec.description = %q{PM2.5 reporting from U.S. Consulate}
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+ require 'pm25/base'
3
+
4
+ describe PM25::Base do
5
+ shared_examples "raise NotImplementedError" do |class_method_name|
6
+ it "should raise NotImplementedError when call #{class_method_name} class method" do
7
+ expect { PM25::Base.__send__ class_method_name }.to raise_error(NotImplementedError, "Please set value for 'city_id' class attributes in 'PM25::Base' class.")
8
+ end
9
+ end
10
+
11
+ shared_examples 'helper methods' do |_class|
12
+ let(:hash_a) do
13
+ {"Conc" => '125.0', "AQI" => '187', "Desc" => "Unhealthy (at 24-hour exposure at this level)", "ReadingDateTime" => "06/04/2013 6:00:00 PM", 'a' => 'a value', 'b' => 'b value'}
14
+ end
15
+
16
+ it 'should slice a hash with ATTRS when call `slice` method' do
17
+ hash_b = _class.slice(hash_a)
18
+ hash_b.should be_a(Hash)
19
+ _class::ATTRS.all?{|x| hash_b.key?(x)}.should eq(true)
20
+ hash_b.key?('a').should eq(false)
21
+ hash_b.key?('b').should eq(false)
22
+ end
23
+
24
+ it 'should parse hash values to ruby data type when call `parse` method' do
25
+ hash_b = _class.parse(hash_a)
26
+ hash_b.should be_a(Hash)
27
+ hash_b.key?('a').should eq(false)
28
+ hash_b.key?('b').should eq(false)
29
+
30
+ hash_b['Conc'].should be_a(Float)
31
+ hash_b['Conc'].should eq(125.0)
32
+ hash_b['AQI'].should be_a(Integer)
33
+ hash_b['AQI'].should eq(187)
34
+ hash_b['ReadingDateTime'].should be_a(DateTime)
35
+ hash_b['ReadingDateTime'].should eq(DateTime.strptime(hash_a['ReadingDateTime'], '%m/%d/%Y %I:%M:%S %p'))
36
+ end
37
+ end
38
+
39
+ context 'Class attributes and constant' do
40
+ it 'should have constant ATTRS with array values' do
41
+ PM25::Base::ATTRS.should eq(%w(Conc AQI Desc ReadingDateTime))
42
+ end
43
+
44
+ it 'should not have city_id' do
45
+ PM25::Base.city_id.should be_nil
46
+ end
47
+
48
+ it 'should have base_uri with host "ww.stateair.net"' do
49
+ PM25::Base.base_uri.should be_a(URI::HTTP)
50
+ PM25::Base.base_uri.host.should eq('www.stateair.net')
51
+ end
52
+ end
53
+
54
+ context 'Class methods' do
55
+ include_examples "raise NotImplementedError", 'uri'
56
+ include_examples "raise NotImplementedError", 'get'
57
+ include_examples "raise NotImplementedError", 'all'
58
+ include_examples "raise NotImplementedError", 'last'
59
+ include_examples "raise NotImplementedError", 'url'
60
+
61
+ include_examples "helper methods", PM25::Base
62
+ end
63
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'pm25/base'
3
+
4
+ shared_examples "city common examples" do |city_class, city_id|
5
+ include_examples "helper methods", city_class
6
+ context 'class attribute' do
7
+ it "should has city_id equal to #{city_id}" do
8
+ city_class.city_id.should_not be_nil
9
+ city_class.city_id.should eq(city_id)
10
+ end
11
+ end
12
+
13
+ context 'class methods' do
14
+ it 'should return an array with pollution data from remote when call `get` method' do
15
+ data = city_class.get
16
+ data.should be_a(Array)
17
+ data.any? {|measure| measure.key? 'AQI'}.should be_true
18
+ end
19
+
20
+ it 'should return an array with clean parsed data clice by ATTRS from remote when call `all` method' do
21
+ data = city_class.all
22
+ measure = data.first
23
+ data.should be_a(Array)
24
+ measure.keys.should eq(city_class::ATTRS)
25
+ measure['Conc'].should be_a(Float)
26
+ measure['AQI'].should be_a(Integer)
27
+ measure['Desc'].should be_a(String)
28
+ measure['ReadingDateTime'].should be_a(DateTime)
29
+ end
30
+
31
+ it 'should return the latest parsed data clice by ATTRS from remote when call `last` method' do
32
+ data = city_class.last
33
+ data.should be_a(Hash)
34
+ data.keys.should eq(city_class::ATTRS)
35
+ data['Conc'].should be_a(Float)
36
+ data['AQI'].should be_a(Integer)
37
+ data['Desc'].should be_a(String)
38
+ data['ReadingDateTime'].should be_a(DateTime)
39
+ end
40
+
41
+ it 'should return URI::HTTP object own context when call `uri` method' do
42
+ uri = city_class.uri
43
+ uri.should be_a(URI::HTTP)
44
+ uri.host.should eq('www.stateair.net')
45
+ uri.path.should eq("/web/rss/1/#{city_id}.xml")
46
+ end
47
+
48
+ it 'should return url string with own context when call `url` method' do
49
+ city_class.url.should be_a(String)
50
+ city_class.url.should eq("http://www.stateair.net/web/rss/1/#{city_id}.xml")
51
+ end
52
+ end
53
+ end
54
+
55
+
56
+ describe PM25::Beijing do
57
+ include_examples "city common examples", PM25::Beijing, '1'
58
+ end
59
+
60
+ describe PM25::Chengdu do
61
+ include_examples "city common examples", PM25::Chengdu, '2'
62
+ end
63
+
64
+ describe PM25::Guangzhou do
65
+ include_examples "city common examples", PM25::Guangzhou, '3'
66
+ end
67
+
68
+ describe PM25::Shanghai do
69
+ include_examples "city common examples", PM25::Shanghai, '4'
70
+ end
71
+
72
+ describe PM25::Shenyang do
73
+ include_examples "city common examples", PM25::Shenyang, '5'
74
+ end
data/spec/pm25_spec.rb CHANGED
@@ -1,11 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Pm25 do
3
+ describe PM25 do
4
4
  it 'should have a version number' do
5
- Pm25::VERSION.should_not be_nil
6
- end
7
-
8
- it 'should do something useful' do
9
- false.should be_false
5
+ PM25::VERSION.should_not be_nil
10
6
  end
11
7
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
1
3
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
4
  require 'pm25'
5
+ require 'rspec/autorun'
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.3
4
+ version: 0.0.4
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-13 00:00:00.000000000 Z
11
+ date: 2013-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,8 @@ files:
104
104
  - lib/pm25/exceptions.rb
105
105
  - lib/pm25/version.rb
106
106
  - pm25.gemspec
107
+ - spec/pm25/base_spec.rb
108
+ - spec/pm25/cities_spec.rb
107
109
  - spec/pm25_spec.rb
108
110
  - spec/spec_helper.rb
109
111
  homepage: ''
@@ -131,5 +133,7 @@ signing_key:
131
133
  specification_version: 4
132
134
  summary: PM2.5 reporting from U.S. Consulate
133
135
  test_files:
136
+ - spec/pm25/base_spec.rb
137
+ - spec/pm25/cities_spec.rb
134
138
  - spec/pm25_spec.rb
135
139
  - spec/spec_helper.rb