Module: Axlsx::Parser

Defined in:
lib/axlsx/util/parser.rb

Overview

The Parser module mixes in a number of methods to help in generating a model from xml This module is not included in the axlsx library at this time. It is for future development only,

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#parser_xmlObject

The xml to be parsed



8
9
10
# File 'lib/axlsx/util/parser.rb', line 8

def parser_xml
  @parser_xml
end

Instance Method Details

#parse_float(attr_name, xpath) ⇒ Object

parse, convert and assign node text to float



30
31
32
33
34
# File 'lib/axlsx/util/parser.rb', line 30

def parse_float attr_name, xpath
  v = parse_value xpath
  v = v.to_f if v.respond_to?(:to_f)
  send("#{attr_name}=", v)
end

#parse_integer(attr_name, xpath) ⇒ Object

parse, convert and assign note text to integer



23
24
25
26
27
# File 'lib/axlsx/util/parser.rb', line 23

def parse_integer attr_name, xpath
  v = parse_value xpath
  v = v.to_i if v.respond_to?(:to_i)
  send("#{attr_name}=", v)
end

#parse_string(attr_name, xpath) ⇒ Object

parse and assign string attribute



11
12
13
# File 'lib/axlsx/util/parser.rb', line 11

def parse_string attr_name, xpath
  send("#{attr_name}=", parse_value(xpath))
end

#parse_symbol(attr_name, xpath) ⇒ Object

parse convert and assign node text to symbol



16
17
18
19
20
# File 'lib/axlsx/util/parser.rb', line 16

def parse_symbol attr_name, xpath
  v = parse_value xpath
  v = v.to_sym unless v.nil?
  send("#{attr_name}=", v)
end

#parse_value(xpath) ⇒ Object

return node text based on xpath



37
38
39
40
41
# File 'lib/axlsx/util/parser.rb', line 37

def parse_value xpath
  node = parser_xml.xpath(xpath)
  return nil if node.empty?
  node.text.strip
end