Class: Reportinator::HelperArrayFunction
Constant Summary
collapse
- PREFIXES =
[">strf", ">offset", ">title", ">sum"]
- INTERVALS =
{
days: {start: "at_beginning_of_day", end: "at_end_of_day"},
weeks: {start: "at_beginning_of_week", end: "at_end_of_week"},
months: {start: "at_beginning_of_month", end: "at_end_of_month"},
years: {start: "at_beginning_of_year", end: "at_end_of_year"}
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
accepts?, #get, #set_attributes
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
Instance Attribute Details
#parsed_target ⇒ Object
64
65
66
|
# File 'lib/reportinator/functions/array/helper.rb', line 64
def parsed_target
@parsed_target ||= parse_target
end
|
#parsed_values ⇒ Object
73
74
75
|
# File 'lib/reportinator/functions/array/helper.rb', line 73
def parsed_values
@parsed_values ||= values.map { |value| parse_value(value) }
end
|
Instance Method Details
#calculate_offset(time, offset, interval, snap) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/reportinator/functions/array/helper.rb', line 43
def calculate_offset(time, offset, interval, snap)
interval = (interval.present? ? interval : :months)
interval = interval.to_s.pluralize.to_sym
return "Invalid Interval" unless INTERVALS.include? interval
interval_data = INTERVALS[interval]
snap = false unless interval_data.include? snap
output = time.advance({interval => offset})
output = output.send(interval_data[snap]) if snap.present?
output
end
|
#output ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/reportinator/functions/array/helper.rb', line 14
def output
return parse_strftime if prefix == ">strf"
return parse_offset if prefix == ">offset"
return parse_title if prefix == ">title"
return parse_sum if prefix == ">sum"
element
end
|
#parse_offset ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/reportinator/functions/array/helper.rb', line 33
def parse_offset
time = target_to_time
return "Invalid Time" if time.nil?
offset = parsed_values[0]
return "Missing Offset" unless offset.present?
interval = parsed_values[1]
snap = parsed_values[2]
calculate_offset(time, offset, interval, snap)
end
|
#parse_strftime ⇒ Object
26
27
28
29
30
31
|
# File 'lib/reportinator/functions/array/helper.rb', line 26
def parse_strftime
time = target_to_time
return "Invalid Time" if time.nil?
return "Invalid Format" unless parsed_values[0].instance_of? String
time.strftime parsed_values[0]
end
|
#parse_sum ⇒ Object
59
60
61
62
|
# File 'lib/reportinator/functions/array/helper.rb', line 59
def parse_sum
sum_values = parsed_values.append parsed_target
sum_values.sum { |value| parse_value("!n #{value}") }
end
|
#parse_target ⇒ Object
68
69
70
71
|
# File 'lib/reportinator/functions/array/helper.rb', line 68
def parse_target
formatted_target = (target.instance_of?(String) ? target.strip : target)
parse_value(formatted_target)
end
|
#parse_title ⇒ Object
54
55
56
57
|
# File 'lib/reportinator/functions/array/helper.rb', line 54
def parse_title
to_join = [parsed_target] + parsed_values
to_join.join(" ").titleize
end
|
#target_to_time ⇒ Object
22
23
24
|
# File 'lib/reportinator/functions/array/helper.rb', line 22
def target_to_time
parsed_target.to_s.to_time
end
|