brighter_planet_metadata 0.1.1 → 0.2.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.
@@ -26,6 +26,23 @@ module BrighterPlanet
26
26
  'certified_emitters' => 'http://certified.impact.brighterplanet.com/emitters.json',
27
27
  'resources' => 'http://data.brighterplanet.com/resources.json',
28
28
  'protocols' => 'http://impact.brighterplanet.com/protocols.json',
29
+
30
+ 'automobiles_options' => 'http://impact.brighterplanet.com/automobiles/options.json',
31
+ 'automobile_trips_options' => 'http://impact.brighterplanet.com/automobile_trips/options.json',
32
+ 'bus_trips_options' => 'http://impact.brighterplanet.com/bus_trips/options.json',
33
+ 'computations_options' => 'http://impact.brighterplanet.com/computations/options.json',
34
+ 'diets_options' => 'http://impact.brighterplanet.com/diets/options.json',
35
+ 'electricity_uses_options' => 'http://impact.brighterplanet.com/electricity_uses/options.json',
36
+ 'flights_options' => 'http://impact.brighterplanet.com/flights/options.json',
37
+ 'fuel_purchases_options' => 'http://impact.brighterplanet.com/fuel_purchases/options.json',
38
+ 'lodgings_options' => 'http://impact.brighterplanet.com/lodgings/options.json',
39
+ 'meetings_options' => 'http://impact.brighterplanet.com/meetings/options.json',
40
+ 'motorcycles_options' => 'http://impact.brighterplanet.com/motorcycles/options.json',
41
+ 'pets_options' => 'http://impact.brighterplanet.com/pets/options.json',
42
+ 'purchases_options' => 'http://impact.brighterplanet.com/purchases/options.json',
43
+ 'rail_trips_options' => 'http://impact.brighterplanet.com/rail_trips/options.json',
44
+ 'residences_options' => 'http://impact.brighterplanet.com/residences/options.json',
45
+ 'shipments_options' => 'http://impact.brighterplanet.com/shipments/options.json',
29
46
  }.freeze
30
47
 
31
48
  # sabshere 2/4/11 obv these have to be updated with some regularity
@@ -61,6 +78,11 @@ module BrighterPlanet
61
78
  def protocols
62
79
  deep_copy_of_authoritative_value_or_fallback 'protocols'
63
80
  end
81
+
82
+ # options (characteristics) available for a given emitter
83
+ def options(emitter)
84
+ deep_copy_of_authoritative_value_or_fallback "#{emitter.to_s.pluralize.downcase}_options"
85
+ end
64
86
 
65
87
  # Clear out any cached values
66
88
  def refresh
@@ -80,19 +102,18 @@ module BrighterPlanet
80
102
  end
81
103
 
82
104
  # Used internally to pull a live list of emitters/datasets/etc. or fall back to a static one.
83
- def authoritative_value_or_fallback(k)
84
- k = k.to_s
85
- if ::ENV['BRIGHTER_PLANET_METADATA_FALLBACKS_ONLY'] == 'true'
86
- $stderr.puts %{ENV['BRIGHTER_PLANET_METADATA_FALLBACKS_ONLY'] == 'true', so using fallback value for '#{k}'}
87
- FALLBACK[k]
105
+ def authoritative_value_or_fallback(meta_name)
106
+ meta_name = meta_name.to_s
107
+ if ::ENV['BRIGHTER_PLANET_METADATA_FALLBACKS_ONLY'] == 'true' && FALLBACK.key?(meta_name)
108
+ $stderr.puts %{ENV['BRIGHTER_PLANET_METADATA_FALLBACKS_ONLY'] == 'true', so using fallback value for '#{meta_name}'}
109
+ FALLBACK[meta_name]
88
110
  else
89
111
  begin
90
- hsh = ::MultiJson.decode ::Net::HTTP.get(::URI.parse(LIVE_URL[k]))
91
- kk = (k == 'certified_emitters') ? 'emitters' : k # the live certified response will contain an 'emitters' key
92
- raise unless hsh.has_key? kk
93
- hsh[kk]
112
+ hsh = ::MultiJson.decode ::Net::HTTP.get(::URI.parse(LIVE_URL[meta_name]))
113
+ subkey = (meta_name == 'certified_emitters') ? 'emitters' : meta_name # the live certified response will contain an 'emitters' key
114
+ hsh.key?(subkey) ? hsh[subkey] : hsh
94
115
  rescue ::Exception
95
- FALLBACK[k]
116
+ FALLBACK[meta_name]
96
117
  end
97
118
  end
98
119
  end
@@ -1,3 +1,3 @@
1
1
  module BrighterPlanetMetadata
2
- VERSION = "0.1.1"
2
+ VERSION = '0.2.0'
3
3
  end
data/test/test_real.rb CHANGED
@@ -28,4 +28,12 @@ class TestReal < Test::Unit::TestCase
28
28
  def test_protocols
29
29
  assert ::BrighterPlanet.metadata.protocols.values.include?('The Climate Registry')
30
30
  end
31
+
32
+ def test_options_flight
33
+ assert ::BrighterPlanet.metadata.options(:flight).keys.include?('fuel_use_coefficients')
34
+ end
35
+
36
+ def test_options_electricity_use
37
+ assert ::BrighterPlanet.metadata.options(:electricity_use).keys.include?('zip_code')
38
+ end
31
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brighter_planet_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-08 00:00:00.000000000 Z
13
+ date: 2012-03-15 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2169290140 !ruby/object:Gem::Requirement
17
+ requirement: &2166662360 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.3.4
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2169290140
25
+ version_requirements: *2166662360
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: i18n
28
- requirement: &2169289720 !ruby/object:Gem::Requirement
28
+ requirement: &2166661940 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2169289720
36
+ version_requirements: *2166661940
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: cache_method
39
- requirement: &2169289260 !ruby/object:Gem::Requirement
39
+ requirement: &2166661480 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2169289260
47
+ version_requirements: *2166661480
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: multi_json
50
- requirement: &2169288800 !ruby/object:Gem::Requirement
50
+ requirement: &2166661060 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *2169288800
58
+ version_requirements: *2166661060
59
59
  description: What emitters (carbon models), resources (data classes), datasets, etc.
60
60
  we offer.
61
61
  email:
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project: brighter_planet_metadata
102
- rubygems_version: 1.8.15
102
+ rubygems_version: 1.8.11
103
103
  signing_key:
104
104
  specification_version: 3
105
105
  summary: Names of Brighter Planet things
@@ -109,4 +109,3 @@ test_files:
109
109
  - test/test_live_remote.rb
110
110
  - test/test_memory_leak.rb
111
111
  - test/test_real.rb
112
- has_rdoc: