Class: ONIX::TwoDigitType
- Inherits:
-
ROXML::XMLRef
- Object
- ROXML::XMLRef
- ONIX::TwoDigitType
- Defined in:
- lib/onix/two_digit_type.rb
Overview
Internal class representing 2-digit XML content
In context:
<element attribute="XMLAttributeRef">
XMLTwoDigitRef
</element>
Instance Attribute Summary collapse
-
#cdata ⇒ Object
readonly
::nodoc::.
-
#content ⇒ Object
readonly
::nodoc::.
Instance Method Summary collapse
-
#initialize(accessor, args, &block) ⇒ TwoDigitType
constructor
A new instance of TwoDigitType.
-
#update_xml(xml, value) ⇒ Object
Updates the text in the given xml block to the value provided.
- #value(xml) ⇒ Object
Constructor Details
#initialize(accessor, args, &block) ⇒ TwoDigitType
Returns a new instance of TwoDigitType.
13 14 15 16 17 |
# File 'lib/onix/two_digit_type.rb', line 13 def initialize(accessor, args, &block) super(accessor, args, &block) @content = args.content? @cdata = args.cdata? end |
Instance Attribute Details
#cdata ⇒ Object (readonly)
- ::nodoc
11 12 13 |
# File 'lib/onix/two_digit_type.rb', line 11 def cdata @cdata end |
#content ⇒ Object (readonly)
- ::nodoc
11 12 13 |
# File 'lib/onix/two_digit_type.rb', line 11 def content @content end |
Instance Method Details
#update_xml(xml, value) ⇒ Object
Updates the text in the given xml block to the value provided.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/onix/two_digit_type.rb', line 21 def update_xml(xml, value) parent = wrap(xml) value = value.to_i if value < 10 value = "0#{value}" elsif value < 100 value = value.to_s else value = "00" end add(parent.child_add(LibXML::XML::Node.new_element(name)), value) xml end |
#value(xml) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/onix/two_digit_type.rb', line 35 def value(xml) if content value = xml.content.to_i else child = xml.search(name).first value = child.content.to_i if child end block ? block.call(value) : value end |