Class: Scorched::Collection

Inherits:
Set
  • Object
show all
Extended by:
DynamicDelegate
Defined in:
lib/scorched/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DynamicDelegate

alias_each, delegate

Instance Attribute Details

#append_parentObject

If true, parent values are appended to self. The default behavior is to append self to the parent values.



11
12
13
# File 'lib/scorched/collection.rb', line 11

def append_parent
  @append_parent
end

Instance Method Details

#inspectObject



35
36
37
# File 'lib/scorched/collection.rb', line 35

def inspect
  "#<#{self.class}(#{super}, #{to_set.inspect})>"
end

#parent!(parent) ⇒ Object

Sets parent Collection object and returns self



14
15
16
17
# File 'lib/scorched/collection.rb', line 14

def parent!(parent)
  @parent = parent
  self
end

#to_a(inherit = true) ⇒ Object



31
32
33
# File 'lib/scorched/collection.rb', line 31

def to_a(inherit = true)
  to_set(inherit).to_a
end

#to_set(inherit = true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/scorched/collection.rb', line 19

def to_set(inherit = true)
  if inherit && (Set === @parent || Array === @parent)
    if append_parent
      Set.new.merge(self._to_a).merge(@parent.to_set)
    else
      Set.new.merge(@parent.to_set).merge(self._to_a)
    end
  else
    Set.new.merge(self._to_a)
  end
end