class Gammo::Attributes

Class for representing attributes.

Attributes

owner_element[RW]

Public Class Methods

new(array, owner_element: nil) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 8
def initialize(array, owner_element: nil)
  super(array)
  array.each { |attr| attr.owner_element = owner_element }
  @owner_element = owner_element
  @attributes_hash = attributes_to_hash(array)
end

Public Instance Methods

<<(attr) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 15
def <<(attr)
  super
  @attributes_hash[attr.key] = attr.value
end
[](key) click to toggle source
# File lib/gammo/attributes.rb, line 20
def [](key)
  @attributes_hash[key.to_s]
end
[]=(key, value) click to toggle source
# File lib/gammo/attributes.rb, line 24
def []=(key, value)
  self << Attribute.new(key: key.to_s, value: value, owner_element: owner_element)
end
append(*attrs) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 49
def append(*attrs)
  super
  attrs.each { |attr| @attributes_hash[attr.key.to_s] = attr.value }
end
Also aliased as: push
delete(attr) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 55
def delete(attr)
  deleted = super
  @attributes_hash.delete(deleted.key) if deleted
  deleted
end
delete_at(pos) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 75
def delete_at(pos)
  deleted = super
  deleted.each { |attr| @attributes_hash.delete(attr.key.to_s) }
  deleted
end
delete_if() click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 68
def delete_if
  original = self.dup
  super
  (original - self).each { |attr| @attributes_hash.delete(attr.key.to_s) }
  self
end
pop(n = nil) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 42
def pop(n = nil)
  original = self.dup
  ret = n ? super : super()
  (original - self).each { |attr| @attributes_hash.delete(attr.key.to_s) }
  ret
end
prepend(*attrs) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 28
def prepend(*attrs)
  prepended = super
  attrs.each { |attr| @attributes_hash[attr.key.to_s] = attr.value }
  prepended
end
Also aliased as: unshift
push(*attrs)
Alias for: append
reject!() click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 61
def reject!
  original = self.dup
  rejected = super
  (original - self).each { |attr| @attributes_hash.delete(attr.key.to_s) }
  rejected
end
shift(n = nil) click to toggle source
Calls superclass method
# File lib/gammo/attributes.rb, line 35
def shift(n = nil)
  original = self.dup
  ret = n ? super : super()
  (original - self).each { |attr| @attributes_hash.delete(attr.key.to_s) }
  ret
end
to_h() click to toggle source
# File lib/gammo/attributes.rb, line 81
def to_h
  @attributes_hash.dup
end
to_s() click to toggle source
# File lib/gammo/attributes.rb, line 85
def to_s
  @attributes_hash.to_s
end
unshift(*attrs)
Alias for: prepend

Private Instance Methods

attributes_to_hash(attrs) click to toggle source
# File lib/gammo/attributes.rb, line 91
def attributes_to_hash(attrs)
  attrs.each_with_object({}) { |attr, h| h[attr.key.to_s] = attr.value }
end