Class: Census::DataSet
- Inherits:
-
Object
- Object
- Census::DataSet
- Defined in:
- lib/rboc/data.rb
Overview
A simple container object that proxies its query method to an underlying DataSetVintage object.
Instance Method Summary collapse
- #[](vintage) ⇒ Object
- #add_vintage(v) ⇒ Object
-
#initialize ⇒ DataSet
constructor
A new instance of DataSet.
- #query(q = Query.new) {|q| ... } ⇒ Object
- #query_raw(q = Query.new) {|q| ... } ⇒ Object
- #vintage_years ⇒ Object
Constructor Details
#initialize ⇒ DataSet
Returns a new instance of DataSet.
102 103 104 105 |
# File 'lib/rboc/data.rb', line 102 def initialize @vintages = {} @newest_vintage = 0 end |
Instance Method Details
#[](vintage) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/rboc/data.rb', line 117 def [](vintage) unless @vintages.keys.include? vintage raise ArgumentError, "Unknown vintage" end @vintages[vintage.to_i] end |
#add_vintage(v) ⇒ Object
107 108 109 110 111 |
# File 'lib/rboc/data.rb', line 107 def add_vintage(v) y = v.vintage @vintages[y] = v @newest_vintage = y if y > @newest_vintage end |
#query(q = Query.new) {|q| ... } ⇒ Object
129 130 131 132 |
# File 'lib/rboc/data.rb', line 129 def query(q=Query.new) yield q if block_given? @vintages[@newest_vintage].query q end |
#query_raw(q = Query.new) {|q| ... } ⇒ Object
124 125 126 127 |
# File 'lib/rboc/data.rb', line 124 def query_raw(q=Query.new) yield q if block_given? @vintages[@newest_vintage].query_raw q end |
#vintage_years ⇒ Object
113 114 115 |
# File 'lib/rboc/data.rb', line 113 def vintage_years @vintages.keys end |