Class: Simmer::Util::RecordSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simmer/util/record_set.rb

Overview

A less-strict comparable collection of Record instances. It does not depend on Record ordering.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records = []) ⇒ RecordSet

Returns a new instance of RecordSet.



23
24
25
26
27
# File 'lib/simmer/util/record_set.rb', line 23

def initialize(records = [])
  @records = array(records).map { |record| Record.new(record) }.sort

  freeze
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



21
22
23
# File 'lib/simmer/util/record_set.rb', line 21

def records
  @records
end

Instance Method Details

#&(other) ⇒ Object



44
45
46
# File 'lib/simmer/util/record_set.rb', line 44

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

#==(other) ⇒ Object Also known as: eql?



29
30
31
# File 'lib/simmer/util/record_set.rb', line 29

def ==(other)
  other.instance_of?(self.class) && records == other.records
end

#keysObject



40
41
42
# File 'lib/simmer/util/record_set.rb', line 40

def keys
  records.flat_map(&:keys)
end

#to_hObject



34
35
36
37
38
# File 'lib/simmer/util/record_set.rb', line 34

def to_h
  {
    'records' => records.map(&:to_h)
  }
end