mcalendar 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +103 -8
- data/lib/mcalendar/command.rb +19 -8
- data/lib/mcalendar/config.rb +1 -70
- data/lib/mcalendar/holiday.rb +42 -43
- data/lib/mcalendar/options.rb +54 -11
- data/lib/mcalendar/output_pdf.rb +5 -3
- data/lib/mcalendar/schedule.rb +82 -0
- data/lib/mcalendar/version.rb +1 -1
- data/lib/mcalendar.rb +2 -0
- data/mcalendar.yml +25 -0
- data/test-unit.yml +12 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 106df652910d9257dddfa3814af1ab493c2ead746ed454c94ce4aa9950014f16
|
4
|
+
data.tar.gz: 6889c7be1874699ac9c86bd96ee7e48f1d61a566c90a78dfb2f398163e86dcda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 953e8b02928a44b6129fc716858aceaf0d29288bd473b3f2e9e2e6dd2a3f7a8276fc1948e403840acb7640b83a68e4f733100c93d2fdc114843c33412823e629
|
7
|
+
data.tar.gz: 027ba073a3567099bf0f18378726925754097826ea8066c1c99b1776e87e90b816f9f6fc9af1cf03b41b1656ade0dc61c1bc2cfbe5e54fb4ffca8680d40d7801
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
# Mcalendar [](https://badge.fury.io/rb/mcalendar)
|
3
3
|
|
4
|
-
Ruby monthly calendar, console and pdf.
|
4
|
+
Ruby monthly calendar, output to console and pdf.
|
5
5
|
This calendar includes Japanese holidays.
|
6
6
|
|
7
7
|
## Installation
|
@@ -29,35 +29,130 @@ When you run the command, the calendar appears on the console. The pdf file is c
|
|
29
29
|
```
|
30
30
|
mcalendar
|
31
31
|
```
|
32
|
+
Output to console and pdf.
|
33
|
+
```
|
34
|
+
September 2021
|
35
|
+
Sun Mon Tue Wed Thu Fri Sat
|
36
|
+
1 2 3 4
|
37
|
+
5 6 7 8 9 10 11
|
38
|
+
12 13 14 15 16 17 18
|
39
|
+
19 20 21 22 23 24 25
|
40
|
+
26 27 28 29 30
|
41
|
+
```
|
42
|
+
|
32
43
|
|
33
|
-
|
44
|
+
Calendar for any month.
|
45
|
+
```
|
46
|
+
mcalendar 2021/02
|
47
|
+
```
|
48
|
+
Output to console and pdf.
|
34
49
|
```
|
35
|
-
mcalendar
|
50
|
+
>mcalendar 2021/02
|
51
|
+
February 2021
|
52
|
+
Sun Mon Tue Wed Thu Fri Sat
|
53
|
+
1 2 3 4 5 6
|
54
|
+
7 8 9 10 11 12 13
|
55
|
+
14 15 16 17 18 19 20
|
56
|
+
21 22 23 24 25 26 27
|
57
|
+
28
|
36
58
|
```
|
37
59
|
|
38
|
-
|
60
|
+
Output only PDF, use the `-p` option.
|
39
61
|
```
|
40
|
-
mcalendar
|
62
|
+
mcalendar 2021/02 -p
|
41
63
|
```
|
42
64
|
|
43
65
|
Also, If you want to output only console, use the `-c` option.
|
44
66
|
```
|
45
|
-
mcalendar
|
67
|
+
mcalendar 2021/02 -c
|
46
68
|
```
|
47
69
|
|
48
70
|
The default PDF file name is `calendar.pdf`. You can specify any name using the `-n` option.
|
49
71
|
```
|
50
|
-
mcalendar
|
72
|
+
mcalendar 2021/02 -n my_calendar.pdf
|
73
|
+
```
|
74
|
+
|
75
|
+
### Configure mcalendar schedule
|
76
|
+
|
77
|
+
mcalendar reads mcalendar.yml in the current working directory as mcalendar's schedule file. It can contain the following settings:
|
78
|
+
* holiday
|
79
|
+
* anniversary
|
80
|
+
|
81
|
+
Here is the included mcalendar.yml as a sample.
|
82
|
+
|
83
|
+
`mcalendar.yml`
|
51
84
|
```
|
85
|
+
holiday:
|
86
|
+
20210101: New Year's Day
|
87
|
+
20210111: Coming-of-age Day
|
88
|
+
20210211: National Foundation Day
|
89
|
+
20210223: Emperor's Birthday
|
90
|
+
20210320: Vernal Equinox Day
|
91
|
+
20210429: Showa Day
|
92
|
+
20210503: Constitution Memorial Day
|
93
|
+
20210504: Greenery Day
|
94
|
+
20210505: Children's Day
|
95
|
+
20210722: Marine Day
|
96
|
+
20210723: Sports Day
|
97
|
+
20210808: Mountain Day
|
98
|
+
20210809: Substitute Holiday
|
99
|
+
20210920: Respect for the Aged Day
|
100
|
+
20210923: Autumnal Equinox Day
|
101
|
+
20211103: Culture Day
|
102
|
+
20211123: Labour Thanksgiving Day
|
103
|
+
|
104
|
+
anniversary:
|
105
|
+
20210224: Ruby's Birthday
|
106
|
+
20210909: RubyKaigi Takeout 2021
|
107
|
+
20210910: RubyKaigi Takeout 2021
|
108
|
+
20210911: RubyKaigi Takeout 2021
|
109
|
+
```
|
110
|
+
|
111
|
+
You can use the command option `-y` or `--holidays` to check the contents of mcalendar.yml.
|
112
|
+
|
113
|
+
```
|
114
|
+
>mcalendar --holidays
|
115
|
+
=========== Holidays ===========
|
116
|
+
20210101: New Year's Day
|
117
|
+
20210111: Coming-of-age Day
|
118
|
+
20210211: National Foundation Day
|
119
|
+
20210223: Emperor's Birthday
|
120
|
+
20210320: Vernal Equinox Day
|
121
|
+
20210429: Showa Day
|
122
|
+
20210503: Constitution Memorial Day
|
123
|
+
20210504: Greenery Day
|
124
|
+
20210505: Children's Day
|
125
|
+
20210722: Marine Day
|
126
|
+
20210723: Sports Day
|
127
|
+
20210808: Mountain Day
|
128
|
+
20210809: Substitute Holiday
|
129
|
+
20210920: Respect for the Aged Day
|
130
|
+
20210923: Autumnal Equinox Day
|
131
|
+
20211103: Culture Day
|
132
|
+
20211123: Labour Thanksgiving Day
|
133
|
+
======== Anniversaries =========
|
134
|
+
20210224: Ruby's Birthday
|
135
|
+
20210909: RubyKaigi Takeout 2021
|
136
|
+
20210910: RubyKaigi Takeout 2021
|
137
|
+
20210911: RubyKaigi Takeout 2021
|
138
|
+
```
|
139
|
+
|
140
|
+
You can also use the command option `-f` or `--config=` to load your own `your_schedule.yml` file.
|
141
|
+
```
|
142
|
+
>mcalendar -f your_schedule.yml
|
143
|
+
```
|
144
|
+
|
52
145
|
|
53
146
|
show help
|
54
147
|
```
|
55
|
-
>mcalendar
|
148
|
+
>mcalendar --help
|
56
149
|
Usage: mcalendar [options]
|
57
150
|
-v, --version Show version
|
58
151
|
-p, --pdf output pdf
|
59
152
|
-n, --name=NAME output pdf name
|
60
153
|
-c, --console output console
|
154
|
+
-f, --config=FILE Use YAML format file.
|
155
|
+
-y, --holidays Display holidays and anniversaries in YAML file
|
61
156
|
```
|
62
157
|
|
63
158
|
## License
|
data/lib/mcalendar/command.rb
CHANGED
@@ -18,6 +18,13 @@ module Mcalendar
|
|
18
18
|
@outputpdf.render_file(pdf_filename)
|
19
19
|
end
|
20
20
|
|
21
|
+
def output_holidays
|
22
|
+
puts "=========== Holidays ==========="
|
23
|
+
puts @schedule.show_holidays
|
24
|
+
puts "======== Anniversaries ========="
|
25
|
+
puts @schedule.show_anniversaries
|
26
|
+
end
|
27
|
+
|
21
28
|
def pdf_filename
|
22
29
|
if @pdf_name.nil? || @pdf_name.empty?
|
23
30
|
Mcalendar::DEFAULT_PDF_NAME
|
@@ -27,25 +34,29 @@ module Mcalendar
|
|
27
34
|
end
|
28
35
|
|
29
36
|
def execute
|
30
|
-
options = Mcalendar::Options.parse(@argv)
|
37
|
+
options = Mcalendar::Options.new.parse(@argv)
|
31
38
|
date = options[:date]
|
32
|
-
console = options[:
|
33
|
-
pdf = options[:
|
34
|
-
@pdf_name = options[:
|
35
|
-
version = options[:
|
39
|
+
console = options[:console]
|
40
|
+
pdf = options[:pdf]
|
41
|
+
@pdf_name = options[:name]
|
42
|
+
version = options[:version]
|
43
|
+
holidays = options[:holidays]
|
44
|
+
|
36
45
|
@calendar = Mcalendar::Calendar.new(date.year, date.month)
|
37
|
-
@
|
46
|
+
@schedule = Mcalendar::Schedule.new(@calendar, options)
|
47
|
+
@outputpdf = Mcalendar::OutputPdf.new(@calendar, @schedule)
|
38
48
|
|
39
49
|
# output calendar
|
40
50
|
output_console if console
|
41
51
|
output_pdf if pdf
|
42
|
-
|
52
|
+
output_holidays if holidays
|
43
53
|
|
44
54
|
# both outputs if no options
|
45
|
-
if console.nil? && pdf.nil? && version.nil?
|
55
|
+
if console.nil? && pdf.nil? && version.nil? && holidays.nil?
|
46
56
|
output_console
|
47
57
|
output_pdf
|
48
58
|
end
|
59
|
+
|
49
60
|
end
|
50
61
|
end
|
51
62
|
end
|
data/lib/mcalendar/config.rb
CHANGED
@@ -22,75 +22,6 @@ module Mcalendar
|
|
22
22
|
DAY_OF_WEEK = %w[Sun Mon Tue Wed Thu Fri Sat].freeze
|
23
23
|
DEFAULT_PDF_NAME = "calendar.pdf".freeze
|
24
24
|
|
25
|
-
|
26
|
-
"ConfigDay",
|
27
|
-
:day,
|
28
|
-
:day_color,
|
29
|
-
:holiday_text,
|
30
|
-
:anniversary_text
|
31
|
-
)
|
25
|
+
DEFAULT_CONFIG_FILE = "mcalendar.yml".freeze
|
32
26
|
|
33
|
-
class Schedule
|
34
|
-
extend Forwardable
|
35
|
-
def_delegators :@calendar, :first_of_month, :end_of_month
|
36
|
-
|
37
|
-
def initialize(calendar)
|
38
|
-
@calendar = calendar
|
39
|
-
@days_config = Hash.new(nil)
|
40
|
-
|
41
|
-
setup_schedule
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def setup_schedule
|
46
|
-
holiday_description_language
|
47
|
-
days_basic
|
48
|
-
holidays_in_the_month
|
49
|
-
anniversaries_in_the_month
|
50
|
-
end
|
51
|
-
|
52
|
-
def holiday_description_language
|
53
|
-
Mcalendar.const_set(:HOLIDAY, Mcalendar::EN::HOLIDAY)
|
54
|
-
Mcalendar.const_set(:ANNIVERSARY, Mcalendar::EN::ANNIVERSARY)
|
55
|
-
end
|
56
|
-
|
57
|
-
def days_basic
|
58
|
-
(first_of_month..end_of_month).each do |date|
|
59
|
-
d_sym = date.strftime("%Y%m%d").to_sym
|
60
|
-
@days_config[d_sym] = Config_day.new(date.day, :black, nil, nil)
|
61
|
-
end
|
62
|
-
@days_config
|
63
|
-
end
|
64
|
-
|
65
|
-
def holidays_in_the_month
|
66
|
-
y = format("%4d", first_of_month.year)
|
67
|
-
m = format("%02d", first_of_month.month)
|
68
|
-
regex = /#{y}#{m}\d\d/
|
69
|
-
|
70
|
-
Mcalendar::HOLIDAY.keys.grep(regex).each do |d|
|
71
|
-
@days_config[d].day = Date.parse(d.to_s).day
|
72
|
-
@days_config[d].day_color = :red
|
73
|
-
@days_config[d].holiday_text = Mcalendar::HOLIDAY[d]
|
74
|
-
end
|
75
|
-
@days_config
|
76
|
-
end
|
77
|
-
|
78
|
-
def anniversaries_in_the_month
|
79
|
-
y = format("%4d", first_of_month.year)
|
80
|
-
m = format("%02d", first_of_month.month)
|
81
|
-
regex = /#{y}#{m}\d\d/
|
82
|
-
|
83
|
-
Mcalendar::ANNIVERSARY.keys.grep(regex).each do |d|
|
84
|
-
@days_config[d].day = Date.parse(d.to_s).day
|
85
|
-
@days_config[d].anniversary_text = Mcalendar::ANNIVERSARY[d]
|
86
|
-
end
|
87
|
-
@days_config
|
88
|
-
end
|
89
|
-
|
90
|
-
def daily_schedule
|
91
|
-
daily = @days_config.each_value.map { |val| val }
|
92
|
-
first_of_month.wday.times { daily.unshift(" ") }
|
93
|
-
daily
|
94
|
-
end
|
95
|
-
end
|
96
27
|
end
|
data/lib/mcalendar/holiday.rb
CHANGED
@@ -1,63 +1,62 @@
|
|
1
1
|
module Mcalendar
|
2
2
|
module JA
|
3
3
|
# Japanese holidays in Japanese
|
4
|
+
# https://www8.cao.go.jp/chosei/shukujitsu/gaiyou.html
|
4
5
|
HOLIDAY = {
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
20
|
-
"
|
21
|
-
"
|
22
|
-
"20201123": "勤労感謝の日",
|
6
|
+
"20210101": "元日",
|
7
|
+
"20210111": "成人の日",
|
8
|
+
"20210211": "建国記念の日",
|
9
|
+
"20210223": "天皇誕生日",
|
10
|
+
"20210320": "春分の日",
|
11
|
+
"20210429": "昭和の日",
|
12
|
+
"20210503": "憲法記念日",
|
13
|
+
"20210504": "みどりの日",
|
14
|
+
"20210505": "子供の日",
|
15
|
+
"20210722": "海の日",
|
16
|
+
"20210723": "スポーツの日",
|
17
|
+
"20210808": "山の日",
|
18
|
+
"20210809": "振替休日",
|
19
|
+
"20210920": "敬老の日",
|
20
|
+
"20210923": "秋分の日",
|
21
|
+
"20211103": "文化の日",
|
22
|
+
"20211123": "勤労感謝の日",
|
23
23
|
}.freeze
|
24
24
|
|
25
25
|
ANNIVERSARY = {
|
26
26
|
"20200224": "Rubyの誕生日",
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"
|
27
|
+
"20200909": "RubyKaigi Takeout 2021",
|
28
|
+
"20200910": "RubyKaigi Takeout 2021",
|
29
|
+
"20200911": "RubyKaigi Takeout 2021",
|
30
30
|
}.freeze
|
31
31
|
end
|
32
32
|
|
33
33
|
module EN
|
34
34
|
# Japanese holidays in English
|
35
35
|
HOLIDAY = {
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
"
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"20201123": "Labour Thanksgiving Day",
|
36
|
+
"20210101": "New Year's Day",
|
37
|
+
"20210111": "Coming-of-age Day",
|
38
|
+
"20210211": "National Foundation Day",
|
39
|
+
"20210223": "Emperor's Birthday",
|
40
|
+
"20210320": "Vernal Equinox Day",
|
41
|
+
"20210429": "Showa Day",
|
42
|
+
"20210503": "Constitution Memorial Day",
|
43
|
+
"20210504": "Greenery Day",
|
44
|
+
"20210505": "Children's Day",
|
45
|
+
"20210722": "Marine Day",
|
46
|
+
"20210723": "Sports Day",
|
47
|
+
"20210808": "Mountain Day",
|
48
|
+
"20210809": "Substitute Holiday",
|
49
|
+
"20210920": "Respect for the Aged Day",
|
50
|
+
"20210923": "Autumnal Equinox Day",
|
51
|
+
"20211103": "Culture Day",
|
52
|
+
"20211123": "Labour Thanksgiving Day",
|
54
53
|
}.freeze
|
55
54
|
|
56
55
|
ANNIVERSARY = {
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
56
|
+
"20210224": "Ruby's Birthday",
|
57
|
+
"20210909": "RubyKaigi Takeout 2021",
|
58
|
+
"20210910": "RubyKaigi Takeout 2021",
|
59
|
+
"20210911": "RubyKaigi Takeout 2021",
|
61
60
|
}.freeze
|
62
61
|
end
|
63
62
|
end
|
data/lib/mcalendar/options.rb
CHANGED
@@ -1,17 +1,59 @@
|
|
1
1
|
module Mcalendar
|
2
|
-
|
3
|
-
def self.parse(argv)
|
4
|
-
options = {}
|
2
|
+
class Options
|
5
3
|
|
4
|
+
def initialize
|
5
|
+
@options = {
|
6
|
+
:holiday => {},
|
7
|
+
:anniversary => {}
|
8
|
+
}
|
9
|
+
|
10
|
+
# If mcalendar.yml is not found, load the built-in mcalendar.yml.
|
11
|
+
if File.exist?(Mcalendar::DEFAULT_CONFIG_FILE)
|
12
|
+
load_config(Mcalendar::DEFAULT_CONFIG_FILE)
|
13
|
+
else
|
14
|
+
config_file = File.expand_path("../../mcalendar.yml",__dir__)
|
15
|
+
load_config(config_file)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash_key_to_sym(h)
|
21
|
+
Hash[h.map{|k, v| [k.to_s.to_sym, v]}]
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_config(file)
|
25
|
+
@config = YAML.load(File.read(file))
|
26
|
+
holidays_schedule
|
27
|
+
anniversaries_schedule
|
28
|
+
end
|
29
|
+
|
30
|
+
def holidays_schedule
|
31
|
+
@options[:holiday] = hash_key_to_sym(@config["holiday"]) if @config["holiday"]
|
32
|
+
end
|
33
|
+
|
34
|
+
def anniversaries_schedule
|
35
|
+
@options[:anniversary] = hash_key_to_sym(@config["anniversary"]) if @config["anniversary"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse(argv)
|
6
39
|
parser = OptionParser.new do |o|
|
7
40
|
o.on_head("-v", "--version", "Show version") do |v|
|
8
|
-
options[:version] = v
|
41
|
+
@options[:version] = v
|
9
42
|
o.version = Mcalendar::VERSION
|
10
43
|
puts o.version
|
11
44
|
end
|
12
|
-
|
13
|
-
o.on("-
|
14
|
-
|
45
|
+
|
46
|
+
o.on("-p", "--pdf", "output pdf") { |v| @options[:pdf] = v }
|
47
|
+
|
48
|
+
o.on("-n NAME", "--name=NAME", String, "output pdf name") { |v| @options[:name] = v }
|
49
|
+
|
50
|
+
o.on("-c", "--console", "output console") { |v| @options[:console] = v }
|
51
|
+
|
52
|
+
o.on("-f FILE", "--config=FILE", "Use YAML format file.") do |file|
|
53
|
+
load_config(file) if file and File.exist?(file)
|
54
|
+
end
|
55
|
+
|
56
|
+
o.on("-y", "--holidays", "Display holidays and anniversaries in YAML file") { |v| @options[:holidays] = v }
|
15
57
|
end
|
16
58
|
|
17
59
|
begin
|
@@ -21,17 +63,18 @@ module Mcalendar
|
|
21
63
|
rescue OptionParser::MissingArgument => e
|
22
64
|
case e.args
|
23
65
|
when ["-n"], ["--name"]
|
24
|
-
options[:name] = Mcalendar::DEFAULT_PDF_NAME
|
66
|
+
@options[:name] = Mcalendar::DEFAULT_PDF_NAME
|
25
67
|
end
|
26
68
|
end
|
27
69
|
|
28
70
|
begin
|
29
|
-
|
71
|
+
@options[:date] = Date.parse(remained.first)
|
30
72
|
rescue
|
31
|
-
|
73
|
+
@options[:date] = Date.today
|
32
74
|
end
|
33
75
|
|
34
|
-
|
76
|
+
@options
|
35
77
|
end
|
78
|
+
|
36
79
|
end
|
37
80
|
end
|
data/lib/mcalendar/output_pdf.rb
CHANGED
@@ -3,13 +3,15 @@ module Mcalendar
|
|
3
3
|
extend Forwardable
|
4
4
|
def_delegator :@calendar, :month_title
|
5
5
|
|
6
|
-
def initialize(calendar)
|
6
|
+
def initialize(calendar, schedule)
|
7
7
|
@calendar = calendar
|
8
|
+
@schedule = schedule
|
9
|
+
|
8
10
|
@month_header = [[month_title]]
|
9
11
|
@day_of_week = [Mcalendar::DAY_OF_WEEK]
|
10
12
|
|
11
|
-
|
12
|
-
@weekly_schedule = schedule.daily_schedule.each_slice(7).map
|
13
|
+
|
14
|
+
@weekly_schedule = @schedule.daily_schedule.each_slice(7).map
|
13
15
|
@day_height = @weekly_schedule.size > 5 ? 20 : 20
|
14
16
|
@text_height = @weekly_schedule.size > 5 ? 30 : 40
|
15
17
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Mcalendar
|
2
|
+
|
3
|
+
class Schedule
|
4
|
+
extend Forwardable
|
5
|
+
def_delegators :@calendar, :first_of_month, :end_of_month
|
6
|
+
|
7
|
+
Config_day = Struct.new(
|
8
|
+
"ConfigDay",
|
9
|
+
:day,
|
10
|
+
:day_color,
|
11
|
+
:holiday_text,
|
12
|
+
:anniversary_text
|
13
|
+
)
|
14
|
+
|
15
|
+
def initialize(calendar, config_schedule)
|
16
|
+
@calendar = calendar
|
17
|
+
@config_schedule = config_schedule
|
18
|
+
@days_config = Hash.new(nil)
|
19
|
+
@holidays = @config_schedule[:holiday]
|
20
|
+
@anniversaries = @config_schedule[:anniversary]
|
21
|
+
|
22
|
+
setup_schedule
|
23
|
+
end
|
24
|
+
|
25
|
+
def show_holidays
|
26
|
+
@holidays.map{|k,v| "#{k}: #{v}"}
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_anniversaries
|
30
|
+
@anniversaries.map{|k,v| "#{k}: #{v}"}
|
31
|
+
end
|
32
|
+
|
33
|
+
def setup_schedule
|
34
|
+
days_basic
|
35
|
+
holidays_in_the_month
|
36
|
+
anniversaries_in_the_month
|
37
|
+
end
|
38
|
+
|
39
|
+
def days_basic
|
40
|
+
(first_of_month..end_of_month).each do |date|
|
41
|
+
d_sym = date.strftime("%Y%m%d").to_sym
|
42
|
+
@days_config[d_sym] = Config_day.new(date.day, :black, nil, nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
@days_config
|
46
|
+
end
|
47
|
+
|
48
|
+
def holidays_in_the_month
|
49
|
+
y = format("%4d", first_of_month.year)
|
50
|
+
m = format("%02d", first_of_month.month)
|
51
|
+
regex = /#{y}#{m}\d\d/
|
52
|
+
|
53
|
+
@holidays.keys.grep(regex).each do |d|
|
54
|
+
@days_config[d].day = Date.parse(d.to_s).day
|
55
|
+
@days_config[d].day_color = :red
|
56
|
+
@days_config[d].holiday_text = @holidays[d]
|
57
|
+
end
|
58
|
+
|
59
|
+
@days_config
|
60
|
+
end
|
61
|
+
|
62
|
+
def anniversaries_in_the_month
|
63
|
+
y = format("%4d", first_of_month.year)
|
64
|
+
m = format("%02d", first_of_month.month)
|
65
|
+
regex = /#{y}#{m}\d\d/
|
66
|
+
|
67
|
+
@anniversaries.keys.grep(regex).each do |d|
|
68
|
+
@days_config[d].day = Date.parse(d.to_s).day
|
69
|
+
@days_config[d].anniversary_text = @anniversaries[d]
|
70
|
+
end
|
71
|
+
|
72
|
+
@days_config
|
73
|
+
end
|
74
|
+
|
75
|
+
def daily_schedule
|
76
|
+
daily = @days_config.each_value.map { |val| val }
|
77
|
+
first_of_month.wday.times { daily.unshift(" ") }
|
78
|
+
daily
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/mcalendar/version.rb
CHANGED
data/lib/mcalendar.rb
CHANGED
@@ -3,6 +3,7 @@ require "prawn"
|
|
3
3
|
require "prawn/table"
|
4
4
|
require "optparse"
|
5
5
|
require 'forwardable'
|
6
|
+
require "yaml"
|
6
7
|
|
7
8
|
require_relative 'mcalendar/calendar'
|
8
9
|
require_relative 'mcalendar/command'
|
@@ -10,4 +11,5 @@ require_relative 'mcalendar/config'
|
|
10
11
|
require_relative 'mcalendar/holiday'
|
11
12
|
require_relative 'mcalendar/options'
|
12
13
|
require_relative 'mcalendar/output_pdf'
|
14
|
+
require_relative 'mcalendar/schedule'
|
13
15
|
require_relative 'mcalendar/version'
|
data/mcalendar.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
holiday:
|
2
|
+
20210101: New Year's Day
|
3
|
+
20210111: Coming-of-age Day
|
4
|
+
20210211: National Foundation Day
|
5
|
+
20210223: Emperor's Birthday
|
6
|
+
20210320: Vernal Equinox Day
|
7
|
+
20210429: Showa Day
|
8
|
+
20210503: Constitution Memorial Day
|
9
|
+
20210504: Greenery Day
|
10
|
+
20210505: Children's Day
|
11
|
+
20210722: Marine Day
|
12
|
+
20210723: Sports Day
|
13
|
+
20210808: Mountain Day
|
14
|
+
20210809: Substitute Holiday
|
15
|
+
20210920: Respect for the Aged Day
|
16
|
+
20210923: Autumnal Equinox Day
|
17
|
+
20211103: Culture Day
|
18
|
+
20211123: Labour Thanksgiving Day
|
19
|
+
|
20
|
+
anniversary:
|
21
|
+
20210224: Ruby's Birthday
|
22
|
+
20210909: RubyKaigi Takeout 2021
|
23
|
+
20210910: RubyKaigi Takeout 2021
|
24
|
+
20210911: RubyKaigi Takeout 2021
|
25
|
+
|
data/test-unit.yml
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcalendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- icm7216
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|
@@ -132,8 +132,11 @@ files:
|
|
132
132
|
- lib/mcalendar/holiday.rb
|
133
133
|
- lib/mcalendar/options.rb
|
134
134
|
- lib/mcalendar/output_pdf.rb
|
135
|
+
- lib/mcalendar/schedule.rb
|
135
136
|
- lib/mcalendar/version.rb
|
136
137
|
- mcalendar.gemspec
|
138
|
+
- mcalendar.yml
|
139
|
+
- test-unit.yml
|
137
140
|
homepage: https://github.com/icm7216/mcalendar
|
138
141
|
licenses:
|
139
142
|
- MIT
|