Class: PluckMap::Attributes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pluck_map/attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Attributes



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pluck_map/attributes.rb', line 7

def initialize(attributes)
  @_attributes = attributes.freeze
  @_attributes_by_id = {}
  @selects = []
  attributes.each do |attribute|
    attribute.indexes = attribute.selects.map do |select|
      selects.find_index(select) || begin
        selects.push(select)
        selects.length - 1
      end
    end
    _attributes_by_id[attribute.id] = attribute
  end
  _attributes_by_id.freeze
end

Instance Attribute Details

#selectsObject (readonly)

Returns the value of attribute selects.



5
6
7
# File 'lib/pluck_map/attributes.rb', line 5

def selects
  @selects
end

Instance Method Details

#==(other) ⇒ Object



51
52
53
54
# File 'lib/pluck_map/attributes.rb', line 51

def ==(other)
  return false if self.class != other.class
  _attributes == other.send(:_attributes)
end

#[](index) ⇒ Object



29
30
31
# File 'lib/pluck_map/attributes.rb', line 29

def [](index)
  _attributes[index]
end

#by_idObject



39
40
41
# File 'lib/pluck_map/attributes.rb', line 39

def by_id
  _attributes_by_id
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/pluck_map/attributes.rb', line 25

def each(&block)
  _attributes.each(&block)
end

#eql?(other) ⇒ Boolean



60
61
62
63
64
# File 'lib/pluck_map/attributes.rb', line 60

def eql?(other)
  return true if self.equal?(other)
  return false if self.class != other.class
  _attributes.eql?(other.send(:_attributes))
end

#hashObject



56
57
58
# File 'lib/pluck_map/attributes.rb', line 56

def hash
  _attributes.hash
end

#lengthObject



33
34
35
# File 'lib/pluck_map/attributes.rb', line 33

def length
  _attributes.length
end

#will_map?Boolean



45
46
47
# File 'lib/pluck_map/attributes.rb', line 45

def will_map?
  _attributes.any?(&:will_map?)
end