Class: EiaFuel::Series

Inherits:
Object
  • Object
show all
Defined in:
lib/eia_fuel/series.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(series = nil) ⇒ Series

Returns a new instance of Series.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/eia_fuel/series.rb', line 20

def initialize(series = nil)
  if series
    [:series_id, :name, :units, :frequency, :unitsshort, :description, :copyright, :source, :iso3166, :geography].each do |var|
      self.instance_variable_set "@#{var}", series[var.to_s]
    end
    @start   = Date.strptime(series["end"], "%Y%m%d")
    @end     = Date.strptime(series["end"], "%Y%m%d")
    @updated = Date.parse(series["updated"])
    @data    = generate_data(series["data"])
  end
end

Instance Attribute Details

Returns the value of attribute copyright.



11
12
13
# File 'lib/eia_fuel/series.rb', line 11

def copyright
  @copyright
end

#dataObject (readonly)

Returns the value of attribute data.



18
19
20
# File 'lib/eia_fuel/series.rb', line 18

def data
  @data
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/eia_fuel/series.rb', line 10

def description
  @description
end

#endObject (readonly)

Returns the value of attribute end.



16
17
18
# File 'lib/eia_fuel/series.rb', line 16

def end
  @end
end

#frequencyObject (readonly)

Returns the value of attribute frequency.



8
9
10
# File 'lib/eia_fuel/series.rb', line 8

def frequency
  @frequency
end

#geographyObject (readonly)

Returns the value of attribute geography.



14
15
16
# File 'lib/eia_fuel/series.rb', line 14

def geography
  @geography
end

#iso3166Object (readonly)

Returns the value of attribute iso3166.



13
14
15
# File 'lib/eia_fuel/series.rb', line 13

def iso3166
  @iso3166
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/eia_fuel/series.rb', line 6

def name
  @name
end

#series_idObject (readonly)

Returns the value of attribute series_id.



5
6
7
# File 'lib/eia_fuel/series.rb', line 5

def series_id
  @series_id
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/eia_fuel/series.rb', line 12

def source
  @source
end

#startObject (readonly)

Returns the value of attribute start.



15
16
17
# File 'lib/eia_fuel/series.rb', line 15

def start
  @start
end

#unitsObject (readonly)

Returns the value of attribute units.



7
8
9
# File 'lib/eia_fuel/series.rb', line 7

def units
  @units
end

#unitsshortObject (readonly)

Returns the value of attribute unitsshort.



9
10
11
# File 'lib/eia_fuel/series.rb', line 9

def unitsshort
  @unitsshort
end

#updatedObject (readonly)

Returns the value of attribute updated.



17
18
19
# File 'lib/eia_fuel/series.rb', line 17

def updated
  @updated
end

Instance Method Details

#latest_priceObject



32
33
34
# File 'lib/eia_fuel/series.rb', line 32

def latest_price
  data.first.price
end