Class: XlsFunction::FormatString::Evaluators::ElapsedTimeEvaluator
- Inherits:
-
Object
- Object
- XlsFunction::FormatString::Evaluators::ElapsedTimeEvaluator
- Defined in:
- lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#half ⇒ Object
readonly
Returns the value of attribute half.
-
#parse_proc ⇒ Object
readonly
Returns the value of attribute parse_proc.
Instance Method Summary collapse
- #call(input) ⇒ Object
- #days_from_origin(time) ⇒ Object
- #hour(time) ⇒ Object
-
#initialize(cache, half: true, &parse_proc) ⇒ ElapsedTimeEvaluator
constructor
A new instance of ElapsedTimeEvaluator.
- #minute(time) ⇒ Object
- #second(time) ⇒ Object
Constructor Details
#initialize(cache, half: true, &parse_proc) ⇒ ElapsedTimeEvaluator
Returns a new instance of ElapsedTimeEvaluator.
10 11 12 13 14 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 10 def initialize(cache, half: true, &parse_proc) @cache = cache @half = half @parse_proc = parse_proc end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 5 def cache @cache end |
#half ⇒ Object (readonly)
Returns the value of attribute half.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 5 def half @half end |
#parse_proc ⇒ Object (readonly)
Returns the value of attribute parse_proc.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 5 def parse_proc @parse_proc end |
Instance Method Details
#call(input) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 16 def call(input) time = ::XlsFunction::Converters::TimeConverter.convert_with_cache(input, cache) result = parse_proc.call(self, time).to_i.to_s half ? result : result.rjust(2, '0') end |
#days_from_origin(time) ⇒ Object
36 37 38 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 36 def days_from_origin(time) time.to_date.to_serial end |
#hour(time) ⇒ Object
23 24 25 26 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 23 def hour(time) elapsed_days = days_from_origin(time) elapsed_days * 24 + time.hour end |
#minute(time) ⇒ Object
28 29 30 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 28 def minute(time) hour(time) * 60 + time.min end |
#second(time) ⇒ Object
32 33 34 |
# File 'lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb', line 32 def second(time) minute(time) * 60 + time.sec end |