Class: OoxmlParser::ValuedChild

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/valued_child.rb

Overview

Class for working with any tag contained only value

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(type = :string, parent: nil) ⇒ ValuedChild

Returns a new instance of ValuedChild.



9
10
11
12
# File 'lib/ooxml_parser/common_parser/common_data/valued_child.rb', line 9

def initialize(type = :string, parent: nil)
  @type = type
  super(parent: parent)
end

Instance Attribute Details

#typeString (readonly)

Returns type of value.

Returns:

  • (String)

    type of value



7
8
9
# File 'lib/ooxml_parser/common_parser/common_data/valued_child.rb', line 7

def type
  @type
end

Instance Method Details

#parse(node) ⇒ ValuedChild

Parse ValuedChild object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ooxml_parser/common_parser/common_data/valued_child.rb', line 17

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'val'
      @value = value.value.to_s if type == :string
      @value = value_to_symbol(value) if type == :symbol
      @value = value.value.to_i if type == :integer
      @value = value.value.to_f if type == :float
      @value = parse_boolean(value.value.to_s) if type == :boolean
    end
  end
  self
end

#valueObject

Returns value of parameter.

Returns:

  • (Object)

    value of parameter



32
33
34
35
36
# File 'lib/ooxml_parser/common_parser/common_data/valued_child.rb', line 32

def value
  return true if type == :boolean && @value.nil?

  @value
end