5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/xls_function/format_string/transform_rules/dates.rb', line 5
def self.included(klass)
klass.class_eval do
rule(year: simple(:year)) do |context|
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
context[:year],
context[:caches]
)
end
rule(month: simple(:month)) do |context|
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
context[:month],
context[:caches],
&:month
)
end
rule(day: simple(:day)) do |context|
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
context[:day],
context[:caches],
&:day
)
end
rule(weekday: simple(:weekday)) do |context|
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
context[:weekday],
context[:caches],
&:weekday
)
end
rule(wareki: simple(:wareki)) do |context|
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
context[:wareki],
context[:caches],
flags: context[:flags],
&:wareki
)
end
rule(gengo: simple(:gengo)) do |context|
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
context[:gengo],
context[:caches],
&:gengo
)
end
rule(gengo_wareki: simple(:gengo_wareki)) do |context|
gengo_func =
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
'ggg',
context[:caches],
&:gengo
).method(:call)
wareki_func =
::XlsFunction::FormatString::Evaluators::TimeEvaluator.new(
'ee',
context[:caches],
&:wareki
).method(:call)
->(input) do
gengo_func.call(input) + wareki_func.call(input)
end
end
rule(gannen: simple(:gannen)) do |context|
context[:flags][:gannen] = true
->(_) { '' }
end
rule(date: subtree(:date)) do
->(input) { date.call(input) }
end
rule(texts: subtree(:texts), date: subtree(:date)) do
->(input) do
"#{texts.map { |expr| expr.call(input) }.join}#{date.call(input)}"
end
end
rule(dates: subtree(:dates)) do
->(input) { Array(dates).flatten.map { |expr| expr.call(input) }.join }
end
end
end
|