Sha256: e8060d2f6719b2cb7ae2e644b1436a0c9de1b72b2a12a1860925d1b1e0e7063d

Contents?: true

Size: 568 Bytes

Versions: 1

Compression:

Stored size: 568 Bytes

Contents

module SequelMapper
  class Dataset
    def initialize(records)
      @records = records
    end

    attr_reader :records
    private     :records

    include Enumerable

    def each(&block)
      records.each(&block)
      self
    end

    def where(criteria)
      new(
        records.select { |row|
          criteria.all? { |k, v|
            row.fetch(k, :nope) == v
          }
        }
      )
    end

    def select(field)
      map { |data| data.fetch(field) }
    end

    private

    def new(records)
      self.class.new(records)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sequel_mapper-0.0.3 lib/sequel_mapper/dataset.rb