Class: XlsFunction::FormatString::Evaluators::ElapsedTimeEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/xls_function/format_string/evaluators/elapsed_time_evaluator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cacheObject (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

#halfObject (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_procObject (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