Class: Duxml::NodeSet

Inherits:
Array show all
Includes:
Observable
Defined in:
lib/duxml/doc/node_set.rb

Overview

subclass of Array that is Observable by History used to track changes in String nodes of XML Element

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_parent, ary = []) ⇒ NodeSet

Returns a new instance of NodeSet.

Parameters:

  • _parent (Element)

    Element that is parent to this NodeSet’s elements

  • ary ([String, Element]) (defaults to: [])

    child nodes with which to initialize this NodeSet



17
18
19
20
# File 'lib/duxml/doc/node_set.rb', line 17

def initialize(_parent, ary=[])
  super ary
  @parent = _parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



13
14
15
# File 'lib/duxml/doc/node_set.rb', line 13

def parent
  @parent
end

Instance Method Details

#[]=(index, str) ⇒ self

Returns reports old String and index to history.

Parameters:

  • index (Fixnum)

    index of array where old String is to be replaced

  • str (String)

    replacing String

Returns:

  • (self)

    reports old String and index to history

Raises:

  • (Exception)


30
31
32
33
34
35
36
37
# File 'lib/duxml/doc/node_set.rb', line 30

def []=(index, str)
  raise Exception if count_observers < 1
  old_str = self[index]
  super(index, str)
  changed
  notify_observers(:ChangeText, parent, index, old_str)
  self
end

#historyHistoryClass

Returns object that observes this NodeSet for changes.

Returns:

  • (HistoryClass)

    object that observes this NodeSet for changes



23
24
25
# File 'lib/duxml/doc/node_set.rb', line 23

def history
  @observer_peers.first.first if @observer_peers and @observer_peers.first.any?
end