Class: Reportinator::ArrayFunction

Inherits:
Function show all
Defined in:
lib/reportinator/functions/array.rb

Constant Summary collapse

PREFIXES =
[]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Function

parse, #parse_and_execute_value, #parse_value, #prefixes

Methods inherited from Base

config, #config, logger, #logger

Methods included from Helpers

#merge_hash, #merge_hash!, #symbolize_attributes

Class Method Details

.accepts?(input) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/reportinator/functions/array.rb', line 9

def self.accepts? input
  return false unless input.instance_of? Array
  return false if self::PREFIXES.empty?
  return false unless input[0].instance_of? String
  self::PREFIXES.each do |prefix|
    return true if input[0].start_with? prefix
  end
  false
end

Instance Method Details

#getObject



19
20
21
22
23
24
25
26
# File 'lib/reportinator/functions/array.rb', line 19

def get
  raise "Function missing output!" unless respond_to? :output
  if set_attributes
    output
  else
    element
  end
end

#set_attributesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/reportinator/functions/array.rb', line 28

def set_attributes
  array = element
  prefix = get_prefix(array[0])
  target_value = array.delete_at(0).sub(prefix, "")
  target_value = array.delete_at(0) if target_value.empty?
  if target_value.to_s.empty?
    false
  else
    self.prefix = prefix
    self.target = target_value
    self.values = array
    true
  end
end