Class: Reportinator::NumberStringFunction
Constant Summary
collapse
- PREFIXES =
["!n", "!nf", "!ni"]
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_body ⇒ Object
13
14
15
16
17
|
# File 'lib/reportinator/functions/string/number.rb', line 13
def parsed_body
to_parse = body
to_parse.strip! if to_parse.instance_of? String
@parsed_body ||= parse_value(body).to_s
end
|
Instance Method Details
#output ⇒ Object
7
8
9
10
11
|
# File 'lib/reportinator/functions/string/number.rb', line 7
def output
return parse_float if prefix == "!nf"
return parse_integer if prefix == "!ni"
parse_number
end
|
#parse_float ⇒ Object
19
20
21
|
# File 'lib/reportinator/functions/string/number.rb', line 19
def parse_float
parsed_body.to_f
end
|
#parse_integer ⇒ Object
23
24
25
|
# File 'lib/reportinator/functions/string/number.rb', line 23
def parse_integer
parsed_body.to_i
end
|
#parse_number ⇒ Object
27
28
29
30
31
|
# File 'lib/reportinator/functions/string/number.rb', line 27
def parse_number
float = (parsed_body =~ /\d\.\d/)
return parse_float if float.present?
parse_integer
end
|