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



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

def parser_xml
  @parser_xml
end

Instance Method Details

#parse_float(attr_name, xpath) ⇒ Object

parse, convert and assign node text to float



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

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

#parse_integer(attr_name, xpath) ⇒ Object

parse, convert and assign note text to integer



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

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

#parse_string(attr_name, xpath) ⇒ Object

parse and assign string attribute



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

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

#parse_symbol(attr_name, xpath) ⇒ Object

parse convert and assign node text to symbol



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

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

#parse_value(xpath) ⇒ Object

return node text based on xpath



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

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