Class: XlsFunction::Evaluators::Functions::Fixed

Inherits:
XlsFunction::Evaluators::FunctionEvaluator show all
Defined in:
lib/xls_function/evaluators/functions/fixed.rb

Constant Summary collapse

DELIMITER_REGEX =
/(\d)(?=(\d\d\d)+(?!\d))/.freeze

Instance Method Summary collapse

Methods inherited from XlsFunction::Evaluators::FunctionEvaluator

#arg_list, #before_eval, #convert_to, create, #detect_error, #error?, #error_message, #eval_arglist, #eval_or_map_eval, #evaluate, #evaluate_or_self, #initialize, #map_eval, to_h, #to_proc, to_proc, translated_description, #variant_context

Methods included from ClassDictionary

included

Methods included from ErrorDetector

#class_info, #class_name, included, #rescue_with

Methods included from ArgumentsDefinable

included

Methods included from Evaluable

#evaluate, included

Constructor Details

This class inherits a constructor from XlsFunction::Evaluators::FunctionEvaluator

Instance Method Details

#delimit(num) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/xls_function/evaluators/functions/fixed.rb', line 34

def delimit(num)
  i, f = num.to_s.split('.')
  i.gsub!(DELIMITER_REGEX) do |digit|
    "#{digit}#{delimiter}"
  end

  [i, f].compact
        .join(separator)
end

#evalObject



15
16
17
18
19
20
21
22
23
# File 'lib/xls_function/evaluators/functions/fixed.rb', line 15

def eval
  rounded = round

  if no_format
    rounded.to_s
  else
    delimit(rounded)
  end
end

#roundObject



25
26
27
28
29
30
31
32
# File 'lib/xls_function/evaluators/functions/fixed.rb', line 25

def round
  n = number.round(digits)
  if digits.positive?
    n.to_f
  else
    n.to_i
  end
end