Class: Toji::Calendar
- Inherits:
-
Object
show all
- Defined in:
- lib/toji/calendar.rb,
lib/toji/calendar/date_row.rb,
lib/toji/calendar/date_column.rb
Defined Under Namespace
Classes: DateColumn, DateRow
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Calendar.
8
9
10
|
# File 'lib/toji/calendar.rb', line 8
def initialize
@products = []
end
|
Instance Attribute Details
#products ⇒ Object
Returns the value of attribute products.
6
7
8
|
# File 'lib/toji/calendar.rb', line 6
def products
@products
end
|
Instance Method Details
#<<(product) ⇒ Object
Also known as:
add
12
13
14
15
|
# File 'lib/toji/calendar.rb', line 12
def <<(product)
@products += [product].flatten
self
end
|
#date_rows ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/toji/calendar.rb', line 18
def date_rows
schedules = @products.map{|product| product.rice_schedules}.flatten
result = {}
schedules.each {|schedule|
result[schedule.date] ||= DateRow.new(schedule.date)
result[schedule.date] << schedule
}
result
end
|
#table ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/toji/calendar.rb', line 105
def table
data = table_text_data
Plotly::Plot.new(
data: [{
type: :table,
header: {
values: data[:header]
},
cells: {
values: data[:rows].transpose
},
}],
layout: {
}
)
end
|
#table_data ⇒ Object
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
|
# File 'lib/toji/calendar.rb', line 30
def table_data
koji_schedules = @products.map{|product| product.koji_schedules}.flatten
kake_schedules = @products.map{|product| product.kake_schedules}.flatten
schedules = koji_schedules + kake_schedules
koji_len = koji_schedules.map{|schedule| schedule.step_weights.first[:index]}.max + 1
kake_len = kake_schedules.map{|schedule| schedule.step_weights.first[:index]}.max + 1
min_date = schedules.map(&:date).min
max_date = schedules.map(&:date).max
= [:date]
case koji_len
when 1
+= [:koji]
when 2
+= [:moto_koji, :moromi_koji]
else
+= [:moto_koji]
(2..koji_len).each {|i|
<< "moromi_koji#{i-1}"
}
end
+= [:moto, :soe, :naka, :tome, :yodan][0...kake_len]
(5...kake_len).each {|i|
<< "#{i}dan"
}
_date_rows = date_rows
rows = []
date = min_date
while date<=max_date
columns = [date.strftime("%m/%d")]
date_row = _date_rows[date]
if date_row
koji_len.times {|i|
columns << date_row.kojis[i]
}
kake_len.times {|i|
columns << date_row.kakes[i]
}
else
(koji_len + kake_len).times {
columns << []
}
end
rows << columns
date = date.tomorrow
end
{header: , rows: rows}
end
|
#table_text_data ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/toji/calendar.rb', line 89
def table_text_data
data = table_data
data[:rows] = data[:rows].map {|row|
row.map {|column|
if DateColumn===column
column.text
elsif column
column
else
""
end
}
}
data
end
|