Class: Reportinator::MethodParser

Inherits:
Parser show all
Defined in:
lib/reportinator/parsers/method.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(target, method) ⇒ Object



6
7
8
9
10
11
# File 'lib/reportinator/parsers/method.rb', line 6

def self.parse(target, method)
  new(target: target, method: method).output
rescue => e
  logger.error "[ERROR] #{e.class}: #{e}"
  "Method Error"
end

Instance Method Details

#method_classObject



23
24
25
# File 'lib/reportinator/parsers/method.rb', line 23

def method_class
  method.class
end

#outputObject



13
14
15
16
17
18
19
20
21
# File 'lib/reportinator/parsers/method.rb', line 13

def output
  if method_class == Symbol
    value = send_value(target, method)
    return escape_value(value)
  end
  return parse_array_method if method_class == Array
  return parse_hash_method if method_class == Hash
  nil
end

#parse_array_methodObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/reportinator/parsers/method.rb', line 27

def parse_array_method
  raise "Not an array" unless method_class == Array
  valid = false
  output = target
  method.each do |m|
    value = parse_method(output, m)
    valid = true
    output = value
  end
  return output if valid
  nil
end

#parse_hash_methodObject



40
41
42
43
44
45
46
# File 'lib/reportinator/parsers/method.rb', line 40

def parse_hash_method
  raise "Not a hash" unless method_class == Hash
  data = method.first
  method = data[0]
  value = data[1]
  send_value(target, method, value)
end