Class: XlsFunction::FormatString::Evaluators::TimeEvaluator
- Inherits:
-
Object
- Object
- XlsFunction::FormatString::Evaluators::TimeEvaluator
- Defined in:
- lib/xls_function/format_string/evaluators/time_evaluator.rb
Instance Attribute Summary collapse
-
#after_effect ⇒ Object
readonly
Returns the value of attribute after_effect.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#minute_mode ⇒ Object
readonly
Returns the value of attribute minute_mode.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #ampm_mode ⇒ Object
- #call(input) ⇒ Object
- #convert_format ⇒ Object
- #convert_to_string(time, format) ⇒ Object
- #day(value) ⇒ Object
- #gannen ⇒ Object
- #gengo(value) ⇒ Object
- #hour(value) ⇒ Object
-
#initialize(source, cache, minute_mode: false, flags: {}, &after_effect) ⇒ TimeEvaluator
constructor
A new instance of TimeEvaluator.
- #minute(value) ⇒ Object
- #modified_source ⇒ Object
-
#month(value) ⇒ Object
↓ after_effects: treat formats not covered by strftime.
- #second(value) ⇒ Object
- #wareki(value) ⇒ Object
- #weekday(value) ⇒ Object
Constructor Details
#initialize(source, cache, minute_mode: false, flags: {}, &after_effect) ⇒ TimeEvaluator
Returns a new instance of TimeEvaluator.
7 8 9 10 11 12 13 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 7 def initialize(source, cache, minute_mode: false, flags: {}, &after_effect) @source = source.to_s @cache = cache @minute_mode = minute_mode @flags = flags @after_effect = after_effect end |
Instance Attribute Details
#after_effect ⇒ Object (readonly)
Returns the value of attribute after_effect.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 5 def after_effect @after_effect end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 5 def cache @cache end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 5 def flags @flags end |
#minute_mode ⇒ Object (readonly)
Returns the value of attribute minute_mode.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 5 def minute_mode @minute_mode end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 5 def source @source end |
Instance Method Details
#ampm_mode ⇒ Object
28 29 30 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 28 def ampm_mode flags[:ampm] end |
#call(input) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 15 def call(input) time = ::XlsFunction::Converters::TimeConverter.convert_with_cache(input, cache) format = convert_format result = convert_to_string(time, format) return result unless after_effect after_effect.call(self, result) end |
#convert_format ⇒ Object
24 25 26 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 24 def convert_format XlsFunction::Converters::TimeConverter.convert_format(modified_source, ampm_mode: ampm_mode) end |
#convert_to_string(time, format) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 36 def convert_to_string(time, format) if format.start_with?('%J') time.to_date.strftime(format) else time.strftime(format) end end |
#day(value) ⇒ Object
52 53 54 55 56 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 52 def day(value) return value[1..] if source == 'd' && value.start_with?('0') value end |
#gannen ⇒ Object
72 73 74 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 72 def gannen flags[:gannen] end |
#gengo(value) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 76 def gengo(value) return ::XlsFunction::Converters::TimeConverter.convert_wareki_to_alphabet(value) if source == 'g' return value[0] if source == 'gg' value end |
#hour(value) ⇒ Object
83 84 85 86 87 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 83 def hour(value) return value[1..] if source == 'h' && value.length == 2 && value.start_with?('0') value end |
#minute(value) ⇒ Object
89 90 91 92 93 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 89 def minute(value) return value[1..] if source == 'm' && value.length == 2 && value.start_with?('0') value end |
#modified_source ⇒ Object
32 33 34 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 32 def modified_source minute_mode ? source.upcase : source.downcase end |
#month(value) ⇒ Object
↓ after_effects: treat formats not covered by strftime
45 46 47 48 49 50 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 45 def month(value) return value[1..] if source == 'm' && value.start_with?('0') return value[0] if source == 'mmmmm' value end |
#second(value) ⇒ Object
95 96 97 98 99 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 95 def second(value) return value[1..] if source == 's' && value.length == 2 && value.start_with?('0') value end |
#wareki(value) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 65 def wareki(value) return '元' if gannen && value == '1' return value.rjust(2, '0') if %w[ee r].include?(source) value end |
#weekday(value) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/xls_function/format_string/evaluators/time_evaluator.rb', line 58 def weekday(value) return ::XlsFunction::Converters::TimeConverter.convert_weekday_jp(value.to_i) if source == 'aaa' return "#{::XlsFunction::Converters::TimeConverter.convert_weekday_jp(value.to_i)}曜日" if source == 'aaaa' value end |