lib/carbon/cli/emitter.rb in carbon-1.0.3 vs lib/carbon/cli/emitter.rb in carbon-1.0.4

- old
+ new

@@ -6,11 +6,11 @@ @emitter = name @input = input characteristics_url = "http://carbon.brighterplanet.com/#{@emitter.to_s.pluralize}/options.json" response = REST.get(characteristics_url) if response.ok? - @characteristics = JSON.parse(response.body) + @characteristics = ActiveSupport::JSON.decode response.body @characteristics.keys.each do |characteristic| instance_eval <<-meth def #{characteristic}(arg = nil) if arg @input[:#{characteristic}] = arg @@ -32,16 +32,25 @@ puts " => Sorry, characteristics couldn't be retrieved for #{@emitter.to_s.pluralize} (via #{url})" done end end + def timeframe(t = nil) + if t + @timeframe = t + emission + else + @timeframe + end + end + def emission puts " => #{emission_in_kilograms} kg CO2e" end def emission_in_kilograms - ::Carbon::EmissionEstimate.new(self).to_f + ::Carbon::EmissionEstimate.new(self, :timeframe => @timeframe).to_f end def lbs puts " => #{emission_in_kilograms.kilograms.to :pounds} lbs CO2e" end @@ -66,22 +75,22 @@ end end end def url - request = ::Carbon::EmissionEstimate.new(self).request + request = ::Carbon::EmissionEstimate.new(self, :timeframe => @timeframe).request url = request.url if request.body.present? url << '?' url << request.body end puts " => #{url}" end def methodology first = true - ::Carbon::EmissionEstimate.new(self).reports.each do |report| + ::Carbon::EmissionEstimate.new(self, :timeframe => @timeframe).reports.each do |report| if first w = ' => ' first = false else w = ' ' @@ -90,10 +99,10 @@ end end def reports first = true - ::Carbon::EmissionEstimate.new(self).reports.each do |report| + ::Carbon::EmissionEstimate.new(self, @timeframe => :timeframe).reports.each do |report| if first w = ' => ' first = false else w = ' '