Class: Trax::Model::UUIDArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/trax/model/uuid_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*uuids) ⇒ UUIDArray

Returns a new instance of UUIDArray.



8
9
10
# File 'lib/trax/model/uuid_array.rb', line 8

def initialize(*uuids)
  @uuids = uuids.map{ |uuid_string| uuid_string.try(&:uuid) }.compact
end

Instance Attribute Details

#uuidsObject (readonly)

Returns the value of attribute uuids.



6
7
8
# File 'lib/trax/model/uuid_array.rb', line 6

def uuids
  @uuids
end

Instance Method Details

#<<(val) ⇒ Object



16
17
18
19
# File 'lib/trax/model/uuid_array.rb', line 16

def <<(val)
  reset_instance_variables(:record_types, :records_grouped_by_count, :records_grouped_by_uuid)
  @uuids.push(::Trax::Model::UUID.new(val))
end

#each {|@uuids.each(&block)| ... } ⇒ Object

Yields:



12
13
14
# File 'lib/trax/model/uuid_array.rb', line 12

def each(&block)
  yield @uuids.each(&block)
end

#recordsObject



21
22
23
24
25
# File 'lib/trax/model/uuid_array.rb', line 21

def records
  @records ||= group_by_record_type.to_a.map{|pair|
    pair[0].by_id(*pair[1])
  }.flatten.compact
end

#records_grouped_by_countObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/trax/model/uuid_array.rb', line 31

def records_grouped_by_count
  @records_grouped_by_count ||= begin
    {}.tap do |hash|
      @uuids.group_by_count.each_pair do |uuid, count|
        record = records_grouped_by_uuid[uuid].first
        hash[record] = count
      end

      hash
    end
  end
end

#records_grouped_by_uuidObject



27
28
29
# File 'lib/trax/model/uuid_array.rb', line 27

def records_grouped_by_uuid
  @records_grouped_by_uuid ||= records.group_by(&:id)
end