Class: XmlParsable::Elements::RecordElement

Inherits:
AbstractElement show all
Defined in:
lib/xmlparsable/elements/record.rb

Defined Under Namespace

Classes: Proxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractElement

#comment, parsable, #read

Constructor Details

#initialize(name, attributes, parent, target, parsers, arguments) ⇒ RecordElement

Returns a new instance of RecordElement.



6
7
8
9
# File 'lib/xmlparsable/elements/record.rb', line 6

def initialize(name, attributes, parent, target, parsers, arguments)
  @name, @attributes, @parent, @target, @parsers, @elements =
    name, attributes, parent, target, parsers, Hash.new{|h,k| h.fetch(k.to_sym, nil) }
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/xmlparsable/elements/record.rb', line 4

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/xmlparsable/elements/record.rb', line 4

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/xmlparsable/elements/record.rb', line 4

def parent
  @parent
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/xmlparsable/elements/record.rb', line 4

def target
  @target
end

Instance Method Details

#close(element, value) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/xmlparsable/elements/record.rb', line 19

def close(element, value)
  parser, arguments = @parsers[element.name]

  if arguments.include?(:repeated)
    (@elements[element.name.to_sym] ||= []) << value
  else
    @elements[element.name.to_sym] = value
  end
end

#finalizeObject



29
30
31
32
33
# File 'lib/xmlparsable/elements/record.rb', line 29

def finalize
  @target.instance_variable_set(:@xmlattrs, @attributes)
  @target.instance_variable_set(:@xmlelems, @elements)
  @parent.close(self, @target) if @parent
end

#open(name, attributes) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/xmlparsable/elements/record.rb', line 11

def open(name, attributes)
  parser, *arguments = @parsers[name]

  if parser
    parser.new(name, attributes, self, *arguments)
  end
end