Class: Reportinator::ReportParser
- Inherits:
-
Parser
show all
- Defined in:
- lib/reportinator/parsers/report.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Parser
#escape_value, get_prefix_list, prefix_list, #prefix_list
Methods inherited from Base
config, #config, logger, #logger
Methods included from Helpers
#merge_hash, #merge_hash!, #symbolize_attributes
Class Method Details
.parse(element, data = nil) ⇒ Object
6
7
8
9
|
# File 'lib/reportinator/parsers/report.rb', line 6
def self.parse(element, data = nil)
set_data = (data.present? ? data : element)
new(element: element, data: set_data).output
end
|
Instance Method Details
#element_class ⇒ Object
37
38
39
|
# File 'lib/reportinator/parsers/report.rb', line 37
def element_class
element.class
end
|
#output ⇒ Object
11
12
13
14
15
16
|
# File 'lib/reportinator/parsers/report.rb', line 11
def output
return parse_array if element_class == Array
return parse_hash if element_class == Hash
return parse_string if element_class == String
element
end
|
#parse_array ⇒ Object
18
19
20
21
|
# File 'lib/reportinator/parsers/report.rb', line 18
def parse_array
raise "Not an array" unless element_class == Array
element.map { |value| parse_value(value) }
end
|
#parse_hash ⇒ Object
23
24
25
26
|
# File 'lib/reportinator/parsers/report.rb', line 23
def parse_hash
raise "Not a hash" unless element_class == Hash
element.transform_values { |value| parse_value(value) }
end
|
#parse_string ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/reportinator/parsers/report.rb', line 28
def parse_string
raise "Not a string" unless element_class == String
return element unless element.strip.start_with?("?")
return element.sub("?/", "") if element.strip.start_with?("?/")
element
end
|