Class: Terrestrial::Dataset
- Inherits:
-
Object
- Object
- Terrestrial::Dataset
- Includes:
- Enumerable
- Defined in:
- lib/terrestrial/dataset.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(records) ⇒ Dataset
constructor
A new instance of Dataset.
- #select(field) ⇒ Object
- #where(criteria) ⇒ Object
Constructor Details
#initialize(records) ⇒ Dataset
Returns a new instance of Dataset.
5 6 7 |
# File 'lib/terrestrial/dataset.rb', line 5 def initialize(records) @records = records end |
Instance Method Details
#each(&block) ⇒ Object
12 13 14 15 |
# File 'lib/terrestrial/dataset.rb', line 12 def each(&block) records.each(&block) self end |
#select(field) ⇒ Object
31 32 33 |
# File 'lib/terrestrial/dataset.rb', line 31 def select(field) map { |data| data.fetch(field) } end |
#where(criteria) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/terrestrial/dataset.rb', line 17 def where(criteria) new( records.find_all { |row| criteria.all? { |k, v| if v.respond_to?(:include?) test_inclusion_in_value(row, k, v) else test_equality(row, k, v) end } } ) end |