Class: ONIX::DecimalType

Inherits:
ROXML::XMLRef
  • Object
show all
Defined in:
lib/onix/decimal_type.rb

Overview

::nodoc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(accessor, args, &block) ⇒ DecimalType

Returns a new instance of DecimalType.



8
9
10
11
12
# File 'lib/onix/decimal_type.rb', line 8

def initialize(accessor, args, &block)
  super(accessor, args, &block)
  @content = args.content?
  @cdata = args.cdata?
end

Instance Attribute Details

#cdataObject (readonly)

Returns the value of attribute cdata.



6
7
8
# File 'lib/onix/decimal_type.rb', line 6

def cdata
  @cdata
end

#contentObject (readonly)

Returns the value of attribute content.



6
7
8
# File 'lib/onix/decimal_type.rb', line 6

def content
  @content
end

Instance Method Details

#update_xml(xml, value) ⇒ Object

Updates the text in the given xml block to the value provided.



16
17
18
19
20
21
22
23
24
25
# File 'lib/onix/decimal_type.rb', line 16

def update_xml(xml, value)
  parent = wrap(xml)
  if value.kind_of?(BigDecimal)
    value = value.to_s("F")
  else
    value = value.to_s
  end
  add(parent.child_add(LibXML::XML::Node.new_element(name)), value)
  xml
end

#value(xml) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/onix/decimal_type.rb', line 27

def value(xml)
  if content
    value = BigDecimal.new(xml.content)
  else
    child = xml.search(name).first
    value = BigDecimal.new(child.content) if child
  end
  block ? block.call(value) : value
end