Class: Nodepile::PileOrganizer::ERecStack

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeERecStack

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.

Parameters:



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_arrayObject



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

#inspectObject



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

Returns:

  • (Boolean)


168
# File 'lib/nodepile/pile_organizer.rb', line 168

def is_edge? = self.type == :edge

#is_impliedObject

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

Returns:

  • (Boolean)


167
# File 'lib/nodepile/pile_organizer.rb', line 167

def is_node? = self.type == :node

#keyObject



165
# File 'lib/nodepile/pile_organizer.rb', line 165

def key() = @a.first['@key']

#purge_rule_overlaysvoid

This method returns an undefined value.

Delete overlayed rule records



183
184
185
186
# File 'lib/nodepile/pile_organizer.rb', line 183

def purge_rule_overlays()
    @a.delete_if{|rec| rec['@type'] == :rule}
    @a.each{|rec| @summary = self.class._update_summary(@summary,rec)}  #recalc
end

#summaryObject



169
# File 'lib/nodepile/pile_organizer.rb', line 169

def summary() = @summary

#to_aObject



170
# File 'lib/nodepile/pile_organizer.rb', line 170

def to_a = @a

#typeObject



164
# File 'lib/nodepile/pile_organizer.rb', line 164

def type = @a.first['@type']