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

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

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)
  @parent = parent
  @type = type
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

#valueString

Returns value of tag.

Returns:

  • (String)

    value of tag



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/valued_child.rb', line 5

def value
  @value
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
# 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
    end
  end
  self
end