Class: Reportinator::ValueParser
- Inherits:
-
Parser
show all
- Defined in:
- lib/reportinator/parsers/value.rb
Constant Summary
collapse
- FORCE_DUP =
[String, Hash, Array]
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, metadata = {}, dup = true) ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/reportinator/parsers/value.rb', line 8
def self.parse(element, metadata = {}, dup = true)
metadata = metadata.present? ? metadata : {}
dup = true if FORCE_DUP.include? element.class
input_element = (dup ? element.dup : element)
new(element: input_element, metadata: metadata).output
rescue => e
logger.error "[ERROR] #{e.class}: #{e}"
"Parsing Error"
end
|
.parse_and_execute(target, values, metadata = {}) ⇒ Object
18
19
20
21
22
|
# File 'lib/reportinator/parsers/value.rb', line 18
def self.parse_and_execute(target, values, metadata = {})
parsed_target = parse(target, metadata, false)
parsed_values = parse(values, metadata)
MethodParser.parse(parsed_target, parsed_values)
end
|
Instance Method Details
#element_class ⇒ Object
43
44
45
|
# File 'lib/reportinator/parsers/value.rb', line 43
def element_class
element.class
end
|
#output ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/reportinator/parsers/value.rb', line 24
def output
config.configured_functions.each do |function|
return function.parse(element, metadata) if function.accepts? element
end
return parse_array if element_class == Array
return parse_hash if element_class == Hash
element
end
|
#parse_array ⇒ Object
33
34
35
36
|
# File 'lib/reportinator/parsers/value.rb', line 33
def parse_array
raise "Not an array" unless element_class == Array
element.map { |value| parse_value(value) }
end
|
#parse_hash ⇒ Object
38
39
40
41
|
# File 'lib/reportinator/parsers/value.rb', line 38
def parse_hash
raise "Not a hash" unless element_class == Hash
element.transform_values { |value| parse_value(value) }
end
|
#parse_value(value) ⇒ Object
47
48
49
|
# File 'lib/reportinator/parsers/value.rb', line 47
def parse_value(value)
self.class.parse(value, metadata)
end
|