Class: BrighterPlanet::Metadata

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/brighter_planet_metadata/metadata.rb

Constant Summary collapse

LIVE_URL =
{
  'datasets'            => 'http://data.brighterplanet.com/datasets.json',
  'emitters'            => 'http://impact.brighterplanet.com/emitters.json',
  'certified_emitters'  => 'http://certified.impact.brighterplanet.com/emitters.json',
  'resources'           => 'http://data.brighterplanet.com/resources.json',
  'protocols'           => 'http://impact.brighterplanet.com/protocols.json',

  'automobiles_options'      => 'http://impact.brighterplanet.com/automobiles/options.json',
  'automobile_trips_options' => 'http://impact.brighterplanet.com/automobile_trips/options.json',
  'bus_trips_options'        => 'http://impact.brighterplanet.com/bus_trips/options.json',
  'computations_options'     => 'http://impact.brighterplanet.com/computations/options.json',
  'diets_options'            => 'http://impact.brighterplanet.com/diets/options.json',
  'electricity_uses_options' => 'http://impact.brighterplanet.com/electricity_uses/options.json',
  'flights_options'          => 'http://impact.brighterplanet.com/flights/options.json',
  'fuel_purchases_options'   => 'http://impact.brighterplanet.com/fuel_purchases/options.json',
  'lodgings_options'         => 'http://impact.brighterplanet.com/lodgings/options.json',
  'meetings_options'         => 'http://impact.brighterplanet.com/meetings/options.json',
  'motorcycles_options'      => 'http://impact.brighterplanet.com/motorcycles/options.json',
  'pets_options'             => 'http://impact.brighterplanet.com/pets/options.json',
  'purchases_options'        => 'http://impact.brighterplanet.com/purchases/options.json',
  'rail_trips_options'       => 'http://impact.brighterplanet.com/rail_trips/options.json',
  'residences_options'       => 'http://impact.brighterplanet.com/residences/options.json',
  'shipments_options'        => 'http://impact.brighterplanet.com/shipments/options.json',

  'automobiles_committees'      => 'http://impact.brighterplanet.com/automobiles/committees.json',
  'automobile_trips_committees' => 'http://impact.brighterplanet.com/automobile_trips/committees.json',
  'bus_trips_committees'        => 'http://impact.brighterplanet.com/bus_trips/committees.json',
  'computations_committees'     => 'http://impact.brighterplanet.com/computations/committees.json',
  'diets_committees'            => 'http://impact.brighterplanet.com/diets/committees.json',
  'electricity_uses_committees' => 'http://impact.brighterplanet.com/electricity_uses/committees.json',
  'flights_committees'          => 'http://impact.brighterplanet.com/flights/committees.json',
  'fuel_purchases_committees'   => 'http://impact.brighterplanet.com/fuel_purchases/committees.json',
  'lodgings_committees'         => 'http://impact.brighterplanet.com/lodgings/committees.json',
  'meetings_committees'         => 'http://impact.brighterplanet.com/meetings/committees.json',
  'motorcycles_committees'      => 'http://impact.brighterplanet.com/motorcycles/committees.json',
  'pets_committees'             => 'http://impact.brighterplanet.com/pets/committees.json',
  'purchases_committees'        => 'http://impact.brighterplanet.com/purchases/committees.json',
  'rail_trips_committees'       => 'http://impact.brighterplanet.com/rail_trips/committees.json',
  'residences_committees'       => 'http://impact.brighterplanet.com/residences/committees.json',
  'shipments_committees'        => 'http://impact.brighterplanet.com/shipments/committees.json',
}.freeze
FALLBACK =
begin
  ::MultiJson.decode(::File.read(::File.expand_path('../fallbacks.json', __FILE__))).freeze
rescue
  $stderr.puts "[brighter_planet_metadata] Error while loading fallbacks. Please reinstall library."
  {}
end

Instance Method Summary collapse

Instance Method Details

#as_cache_keyObject

for cache_method



114
115
116
# File 'lib/brighter_planet_metadata/metadata.rb', line 114

def as_cache_key
  'BrighterPlanet::Metadata.instance'
end

#certified_emittersObject

What certified_emitters are available.



78
79
80
# File 'lib/brighter_planet_metadata/metadata.rb', line 78

def certified_emitters
  deep_copy_of_authoritative_value_or_fallback 'certified_emitters'
end

#committees(emitter) ⇒ Object

committees (decisions) available for a given emitter



103
104
105
# File 'lib/brighter_planet_metadata/metadata.rb', line 103

def committees(emitter)
  deep_copy_of_authoritative_value_or_fallback "#{emitter.to_s.pluralize.downcase}_committees"
end

#datasetsObject

What datasets are available.



88
89
90
# File 'lib/brighter_planet_metadata/metadata.rb', line 88

def datasets
  deep_copy_of_authoritative_value_or_fallback 'datasets'
end

#emittersObject

What emitters are available.



83
84
85
# File 'lib/brighter_planet_metadata/metadata.rb', line 83

def emitters
  deep_copy_of_authoritative_value_or_fallback 'emitters'
end

#options(emitter) ⇒ Object

options (characteristics) available for a given emitter



98
99
100
# File 'lib/brighter_planet_metadata/metadata.rb', line 98

def options(emitter)
  deep_copy_of_authoritative_value_or_fallback "#{emitter.to_s.pluralize.downcase}_options"
end

#protocolsObject

What protocols are recognized



93
94
95
# File 'lib/brighter_planet_metadata/metadata.rb', line 93

def protocols
  deep_copy_of_authoritative_value_or_fallback 'protocols'
end

#refreshObject

Clear out any cached values



108
109
110
111
# File 'lib/brighter_planet_metadata/metadata.rb', line 108

def refresh
  # instance_variables.each { |ivar_name| instance_variable_set ivar_name, nil }
  cache_method_clear :authoritative_value_or_fallback
end

#resourcesObject

What resources are available.



73
74
75
# File 'lib/brighter_planet_metadata/metadata.rb', line 73

def resources
  deep_copy_of_authoritative_value_or_fallback 'resources'
end