class Terrestrial::Dataset

Attributes

records[R]

Public Class Methods

new(records) click to toggle source
# File lib/terrestrial/dataset.rb, line 5
def initialize(records)
  @records = records
end

Public Instance Methods

each(&block) click to toggle source
# File lib/terrestrial/dataset.rb, line 12
def each(&block)
  records.each(&block)
  self
end
select(field) click to toggle source
# File lib/terrestrial/dataset.rb, line 31
def select(field)
  map { |data| data.fetch(field) }
end
where(criteria) click to toggle source
# 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

Private Instance Methods

new(records) click to toggle source
# File lib/terrestrial/dataset.rb, line 37
def new(records)
  self.class.new(records)
end
test_equality(row, field, value) click to toggle source
# File lib/terrestrial/dataset.rb, line 45
def test_equality(row, field, value)
  value == row.fetch(field)
end
test_inclusion_in_value(row, field, values) click to toggle source
# File lib/terrestrial/dataset.rb, line 41
def test_inclusion_in_value(row, field, values)
  values.include?(row.fetch(field))
end