Class: Nodepile::PileOrganizer::ERecStack
- Inherits:
-
Object
- Object
- Nodepile::PileOrganizer::ERecStack
- Defined in:
- lib/nodepile/pile_organizer.rb,
lib/nodepile/pile_organizer.rb
Overview
An ERecStack is a data structure used for holding and summarizing overlay-able records related to a given Node or Edge which can include “rules” that apply to that node/stack
Instance Method Summary collapse
-
#<<(rec) ⇒ Object
Note that this method does not verify whether it is appropriate to stack the new record and assumes callers have alreay done this due-diligence.
- #each_keyed_array ⇒ Object
-
#initialize ⇒ ERecStack
constructor
A new instance of ERecStack.
- #inspect ⇒ Object
- #is_edge? ⇒ Boolean
-
#is_implied ⇒ Object
A stack of type :node or :edge is implied if it contains no ERec records where the is_implied attribute is false.
- #is_node? ⇒ Boolean
- #key ⇒ Object
-
#purge_rule_overlays ⇒ void
Delete overlayed rule records.
- #summary ⇒ Object
- #to_a ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize ⇒ ERecStack
Returns a new instance of ERecStack.
153 154 155 156 157 |
# File 'lib/nodepile/pile_organizer.rb', line 153 def initialize() @a = Array.new @summary = nil @mc = CrudeCalculationCache.new end |
Instance Method Details
#<<(rec) ⇒ Object
Note that this method does not verify whether it is appropriate to stack the new record and assumes callers have alreay done this due-diligence.
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/nodepile/pile_organizer.rb', line 192 def <<(rec) raise "ERecStack may only hold objects of type Nodepile::KeyedArrayAccessor" unless rec.is_a?(Nodepile::KeyedArrayAccessor) # Keep the summary up-to-date if we've got one. @a << rec if @a.length == 1 @summary = rec.dup else @summary = self.class._update_summary(@summary,rec) end return self end |
#each_keyed_array ⇒ Object
204 205 206 207 |
# File 'lib/nodepile/pile_organizer.rb', line 204 def each_keyed_array() return enum_for(:each_keyed_array) unless block_given? @a.each{|erec| yield erec } end |
#inspect ⇒ Object
159 160 161 |
# File 'lib/nodepile/pile_organizer.rb', line 159 def inspect "#<#{self.class}:0x#{object_id} type= #{type} key=#{self.key.inspect} depth=#{@a.length}> " end |
#is_edge? ⇒ Boolean
168 |
# File 'lib/nodepile/pile_organizer.rb', line 168 def is_edge? = self.type == :edge |
#is_implied ⇒ Object
A stack of type :node or :edge is implied if it contains no ERec records where the is_implied attribute is false. The return value of this method is undefined for types
175 176 177 178 179 |
# File 'lib/nodepile/pile_organizer.rb', line 175 def is_implied @a.each{|kaa| return false if !kaa['@is_implied'] && [:node,:edge].include?(kaa['@type']) } return true end |
#is_node? ⇒ Boolean
167 |
# File 'lib/nodepile/pile_organizer.rb', line 167 def is_node? = self.type == :node |
#key ⇒ Object
165 |
# File 'lib/nodepile/pile_organizer.rb', line 165 def key() = @a.first['@key'] |
#purge_rule_overlays ⇒ void
This method returns an undefined value.
Delete overlayed rule records
183 184 185 186 |
# File 'lib/nodepile/pile_organizer.rb', line 183 def () @a.delete_if{|rec| rec['@type'] == :rule} @a.each{|rec| @summary = self.class._update_summary(@summary,rec)} #recalc end |
#summary ⇒ Object
169 |
# File 'lib/nodepile/pile_organizer.rb', line 169 def summary() = @summary |
#to_a ⇒ Object
170 |
# File 'lib/nodepile/pile_organizer.rb', line 170 def to_a = @a |
#type ⇒ Object
164 |
# File 'lib/nodepile/pile_organizer.rb', line 164 def type = @a.first['@type'] |