Class: BLS_API::Series
- Inherits:
-
Object
- Object
- BLS_API::Series
- Includes:
- Destringify
- Defined in:
- lib/bls_api/series.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#catalog ⇒ Object
Public: Return catalog information for this series if available.
-
#get_month(year, month) ⇒ Object
Public: Return information for the given month.
-
#initialize(raw_series) ⇒ Series
constructor
A new instance of Series.
-
#monthly ⇒ Object
Public: Return information for all months.
Methods included from Destringify
#destringify, #destringify_calculations, #destringify_month, #destringify_series
Constructor Details
#initialize(raw_series) ⇒ Series
Returns a new instance of Series.
11 12 13 14 15 16 17 18 19 |
# File 'lib/bls_api/series.rb', line 11 def initialize(raw_series) @id = raw_series["seriesID"] begin @raw_series = self.destringify_series(raw_series) rescue ArgumentError # Series was already destringified _and_ it was using Floats. @raw_series = raw_series end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/bls_api/series.rb', line 9 def id @id end |
Instance Method Details
#catalog ⇒ Object
Public: Return catalog information for this series if available.
Returns an OpenStruct if possible; returns nil if no catalog information
was received.
25 26 27 28 29 |
# File 'lib/bls_api/series.rb', line 25 def catalog return nil unless @raw_series.include?("catalog") return @catalog unless @catalog.nil? @catalog = OpenStruct.new(@raw_series["catalog"]) end |
#get_month(year, month) ⇒ Object
Public: Return information for the given month.
year - An Integer representing the year for which to retrieve data. month - An Integer representing the month (1 = January) for which to
retrieve data.
Returns a BLS_API::Month.
38 39 40 41 42 43 |
# File 'lib/bls_api/series.rb', line 38 def get_month(year, month) self.monthly # Ensure we've converted all months. @months.detect do |parsed_month| parsed_month.year == year && parsed_month.month == month end end |
#monthly ⇒ Object
Public: Return information for all months.
Returns an Array of BLS_API::Months.
48 49 50 51 52 53 54 |
# File 'lib/bls_api/series.rb', line 48 def monthly return @months unless @months.nil? @months = @raw_series["data"].map do |month_data| BLS_API::Month.new(month_data) end @months.sort!.reverse! end |