mcalendar 0.3.7 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c37d4882b2dcea8a3df4b7e8802b319ccbfd1f650fe2fc90e6fb6fafa9919d3
4
- data.tar.gz: f6005e4ea03becf4302e45490dcd4a0f00230d6db48d1bec4d6411f7d45c9560
3
+ metadata.gz: e0ba0d5eb52a4d7229c2a6e44d19b5d88cb48f429ee26756e94f5ff57c6da889
4
+ data.tar.gz: ff7860a811535caf70ddd900546ea0cffc1fa36c58b0bc53a7577ce020b82aa7
5
5
  SHA512:
6
- metadata.gz: '093c36d9b6ccfc75fe69e9c7fe4a406202e24c8592738f0b572f26dfe51802beadee078cfd84e32d4a2ee197406d1b2a97acb9b08e47de98efd1a3efd1f1ccb7'
7
- data.tar.gz: ca679323931aaa7cdf0803c2a386b15c23f20d2ecf0902769f4e7e2a770ea5fb8124c1eada288e0847e4dbaaf92045b3a248060cef24ed37828a9cdd7f188690
6
+ metadata.gz: 694f1a3e42c289590ea5140b8f2959e5924fcd219f5b43a4123c3293b6468f80c3c162ba9667cb00d1f25c1ace2602e2685d38e2b610dd6adabaa448541246f4
7
+ data.tar.gz: 5eee6f4f6e9afb2fca6a8a028ddd983bb057015677e58d3ffc92b34cb0766277072a36ed526cafe22e3f427d4f1d307a0c8c7fb86b260476959dfa51dbe091a3
data/.gitignore CHANGED
@@ -1,12 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /Gemfile.lock
10
- pdf/*.pdf
11
- *.pdf
12
- /.vscode/
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+ pdf/*.pdf
11
+ *.pdf
12
+ /.vscode/
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in mcalendar.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 12.0"
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mcalendar.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,65 +1,160 @@
1
-
2
- # Mcalendar [![Gem Version](https://badge.fury.io/rb/mcalendar.svg)](https://badge.fury.io/rb/mcalendar)
3
-
4
- Ruby monthly calendar, console and pdf.
5
- This calendar includes Japanese holidays.
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'mcalendar'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install mcalendar
22
-
23
-
24
- ## Usage
25
-
26
- If you want to create a calendar for this month.
27
-
28
- When you run the command, the calendar appears on the console. The pdf file is created in the current directory.
29
- ```
30
- mcalendar
31
- ```
32
-
33
- If you want to create a calendar for any month.
34
- ```
35
- mcalendar 2020/02
36
- ```
37
-
38
- If you want to output only PDF, use the `-p` option.
39
- ```
40
- mcalendar 2020/02 -p
41
- ```
42
-
43
- Also, If you want to output only console, use the `-c` option.
44
- ```
45
- mcalendar 2020/02 -c
46
- ```
47
-
48
- The default PDF file name is `calendar.pdf`. You can specify any name using the `-n` option.
49
- ```
50
- mcalendar 2020/02 -n my_calendar.pdf
51
- ```
52
-
53
- show help
54
- ```
55
- >mcalendar -h
56
- Usage: mcalendar [options]
57
- -v, --version Show version
58
- -p, --pdf output pdf
59
- -n, --name=NAME output pdf name
60
- -c, --console output console
61
- ```
62
-
63
- ## License
64
-
65
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1
+
2
+ # Mcalendar [![Gem Version](https://badge.fury.io/rb/mcalendar.svg)](https://badge.fury.io/rb/mcalendar)
3
+
4
+ Ruby monthly calendar, output to console and pdf.
5
+ This calendar includes Japanese holidays.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mcalendar'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mcalendar
22
+
23
+
24
+ ## Usage
25
+
26
+ If you want to create a calendar for this month.
27
+
28
+ When you run the command, the calendar appears on the console. The pdf file is created in the current directory.
29
+ ```
30
+ mcalendar
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
+
43
+
44
+ Calendar for any month.
45
+ ```
46
+ mcalendar 2021/02
47
+ ```
48
+ Output to console and pdf.
49
+ ```
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
58
+ ```
59
+
60
+ Output only PDF, use the `-p` option.
61
+ ```
62
+ mcalendar 2021/02 -p
63
+ ```
64
+
65
+ Also, If you want to output only console, use the `-c` option.
66
+ ```
67
+ mcalendar 2021/02 -c
68
+ ```
69
+
70
+ The default PDF file name is `calendar.pdf`. You can specify any name using the `-n` option.
71
+ ```
72
+ mcalendar 2021/02 -n my_calendar.pdf
73
+ ```
74
+
75
+ ### Configure mcalendar schedule
76
+
77
+ mcalendar reads `~/.mcalendar.yml` or `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`
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
+
145
+
146
+ show help
147
+ ```
148
+ >mcalendar --help
149
+ Usage: mcalendar [options]
150
+ -v, --version Show version
151
+ -p, --pdf output pdf
152
+ -n, --name=NAME output pdf name
153
+ -c, --console output console
154
+ -f, --config=FILE Use YAML format file.
155
+ -y, --holidays Display holidays and anniversaries in YAML file
156
+ ```
157
+
158
+ ## License
159
+
160
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -2,41 +2,37 @@
2
2
  module Mcalendar
3
3
 
4
4
  class Calendar
5
- attr_reader :pdf_name, :month_title, :days, :first_of_month, :end_of_month
6
5
 
7
- def initialize(year, month, pdf_name)
8
- @first_of_month = Date.new(year, month, 1)
9
- @end_of_month = Date.new(year, month, -1)
10
- @days = (1..end_of_month.day).map {|m| "%2d" % m}
11
- first_of_month.wday.times {@days.unshift(" ")}
12
- @month_title = first_of_month.strftime("%B %Y")
13
- set_pdf_name(pdf_name)
6
+ def initialize(year, month)
7
+ @year = year
8
+ @month = month
14
9
  end
15
10
 
16
- def set_pdf_name(name)
17
- if name.nil? || name.empty?
18
- @pdf_name = Mcalendar::DEFAULT_PDF_NAME
19
- else
20
- @pdf_name = name
21
- end
11
+ def first_of_month
12
+ Date.new(@year, @month, 1)
13
+ end
14
+
15
+ def end_of_month
16
+ Date.new(@year, @month, -1)
17
+ end
18
+
19
+ def days
20
+ days = (1..end_of_month.day).map {|m| "%2d" % m}
21
+ first_of_month.wday.times {days.unshift(" ")}
22
+ days
23
+ end
24
+
25
+ def month_title
26
+ first_of_month.strftime("%B %Y")
22
27
  end
23
28
 
24
29
  def to_s
25
30
  week_header = Mcalendar::DAY_OF_WEEK.join(" ")
26
- month_header = @month_title.center(week_header.size).rstrip
31
+ month_header = month_title.center(week_header.size).rstrip
27
32
  calendar = [[week_header]]
28
- @days.each_slice(7) {|x| calendar << [x.join(" ")]}
33
+ days.each_slice(7) {|x| calendar << [x.join(" ")]}
29
34
  [month_header, calendar]
30
35
  end
31
-
32
- def display
33
- puts to_s
34
- end
35
-
36
- def pdf
37
- pdf = Mcalendar::OutputPdf.new(self)
38
- pdf.render_file @pdf_name
39
- end
40
36
 
41
37
  end
42
38
  end
@@ -9,25 +9,54 @@ module Mcalendar
9
9
  def initialize(argv)
10
10
  @argv = argv
11
11
  end
12
+
13
+ def output_console
14
+ puts @calendar.to_s
15
+ end
16
+
17
+ def output_pdf
18
+ @outputpdf.render_file(pdf_filename)
19
+ end
20
+
21
+ def output_holidays
22
+ puts "=========== Holidays ==========="
23
+ puts @schedule.show_holidays
24
+ puts "======== Anniversaries ========="
25
+ puts @schedule.show_anniversaries
26
+ end
27
+
28
+ def pdf_filename
29
+ if @pdf_name.nil? || @pdf_name.empty?
30
+ Mcalendar::DEFAULT_PDF_NAME
31
+ else
32
+ @pdf_name = @pdf_name.downcase.end_with?(".pdf")? @pdf_name : @pdf_name + ".pdf"
33
+ end
34
+ end
12
35
 
13
36
  def execute
14
- options = Mcalendar::Options.parse(@argv)
37
+ options = Mcalendar::Options.new.parse(@argv)
15
38
  date = options[:date]
16
- console = options[:opt][:console]
17
- pdf = options[:opt][:pdf]
18
- pdf_name = options[:opt][:name]
19
- version = options[:opt][:version]
20
- calendar = Mcalendar::Calendar.new(date.year, date.month, pdf_name)
39
+ console = options[:console]
40
+ pdf = options[:pdf]
41
+ @pdf_name = options[:name]
42
+ version = options[:version]
43
+ holidays = options[:holidays]
44
+
45
+ @calendar = Mcalendar::Calendar.new(date.year, date.month)
46
+ @schedule = Mcalendar::Schedule.new(@calendar, options)
47
+ @outputpdf = Mcalendar::OutputPdf.new(@calendar, @schedule)
21
48
 
22
49
  # output calendar
23
- calendar.display if console
24
- calendar.pdf if pdf
50
+ output_console if console
51
+ output_pdf if pdf
52
+ output_holidays if holidays
25
53
 
26
54
  # both outputs if no options
27
- if console.nil? && pdf.nil? && version.nil?
28
- calendar.display
29
- calendar.pdf
55
+ if console.nil? && pdf.nil? && version.nil? && holidays.nil?
56
+ output_console
57
+ output_pdf
30
58
  end
59
+
31
60
  end
32
61
  end
33
62
  end
@@ -22,65 +22,7 @@ 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
- Config_day = Struct.new(
26
- "ConfigDay",
27
- :day,
28
- :day_color,
29
- :holiday_text,
30
- :anniversary_text
31
- )
32
-
33
- module Config
34
- def days_information
35
- # @first_of_month = obj_calendar.first_of_month
36
- # @end_of_month = obj_calendar.end_of_month
37
-
38
- @days_config = Hash.new(nil)
39
- holiday_description_language
40
- days_basic
41
- holiday
42
- anniversary
43
- end
44
-
45
- def days_basic
46
- (@first_of_month..@end_of_month).each do |date|
47
- d_sym = date.strftime("%Y%m%d").to_sym
48
- @days_config[d_sym] = Config_day.new(date.day, :black, nil, nil)
49
- end
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 holiday
58
- y = format("%4d", @first_of_month.year)
59
- m = format("%02d", @first_of_month.month)
60
- regex = /#{y}#{m}\d\d/
61
-
62
- Mcalendar::HOLIDAY.keys.grep(regex).each do |d|
63
- @days_config[d].day = Date.parse(d.to_s).day
64
- @days_config[d].day_color = :red
65
- @days_config[d].holiday_text = Mcalendar::HOLIDAY[d]
66
- end
67
- end
68
-
69
- def anniversary
70
- y = format("%4d", @first_of_month.year)
71
- m = format("%02d", @first_of_month.month)
72
- regex = /#{y}#{m}\d\d/
73
-
74
- Mcalendar::ANNIVERSARY.keys.grep(regex).each do |d|
75
- @days_config[d].day = Date.parse(d.to_s).day
76
- @days_config[d].anniversary_text = Mcalendar::ANNIVERSARY[d]
77
- end
78
- end
79
-
80
- def days
81
- pdf_days = @days_config.each_value.map { |val| val }
82
- @first_of_month.wday.times { pdf_days.unshift(" ") }
83
- pdf_days
84
- end
85
- end
25
+ DEFAULT_CONFIG_FILE = "mcalendar.yml".freeze
26
+ GLOBAL_CONFIG_FILE = File.expand_path("~/.mcalendar.yml").freeze
27
+ BUILT_IN_CONFIG_FILE = File.expand_path("../../mcalendar.yml", __dir__).freeze
86
28
  end
@@ -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
- "20200101": "元日",
6
- "20200113": "成人の日",
7
- "20200211": "建国記念の日",
8
- "20200223": "天皇誕生日",
9
- "20200224": "振替休日",
10
- "20200320": "春分の日",
11
- "20200429": "昭和の日",
12
- "20200503": "憲法記念日",
13
- "20200504": "みどりの日",
14
- "20200505": "子供の日",
15
- "20200506": "振替休日",
16
- "20200723": "海の日",
17
- "20200724": "スポーツの日",
18
- "20200810": "山の日",
19
- "20200921": "敬老の日",
20
- "20200922": "秋分の日",
21
- "20201103": "文化の日",
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
- "20200903": "RubyKaigi 2020 Nagano",
28
- "20200904": "RubyKaigi 2020 Nagano",
29
- "20200905": "RubyKaigi 2020 Nagano",
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
- "20200101": "New Year's Day",
37
- "20200113": "Coming-of-age Day",
38
- "20200211": "National Foundation Day",
39
- "20200223": "Emperor's Birthday",
40
- "20200224": "Substitute Holiday",
41
- "20200320": "Vernal Equinox Day",
42
- "20200429": "Showa Day",
43
- "20200503": "Constitution Memorial Day",
44
- "20200504": "Greenery Day",
45
- "20200505": "Children's Day",
46
- "20200506": "Substitute Holiday",
47
- "20200723": "Marine Day",
48
- "20200724": "Sports Day",
49
- "20200810": "Mountain Day",
50
- "20200921": "Respect for the Aged Day",
51
- "20200922": "Autumnal Equinox Day",
52
- "20201103": "Culture Day",
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
- "20200224": "Ruby's Birthday",
58
- "20200903": "RubyKaigi 2020 Nagano",
59
- "20200904": "RubyKaigi 2020 Nagano",
60
- "20200905": "RubyKaigi 2020 Nagano",
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
@@ -1,37 +1,84 @@
1
1
  module Mcalendar
2
- module Options
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 or ~/.mcalendar.yml is not found, load the built-in mcalendar.yml.
11
+ if File.exist?(Mcalendar::DEFAULT_CONFIG_FILE)
12
+ config_yaml = Mcalendar::DEFAULT_CONFIG_FILE
13
+ elsif File.exist?(Mcalendar::GLOBAL_CONFIG_FILE)
14
+ config_yaml = Mcalendar::GLOBAL_CONFIG_FILE
15
+ else
16
+ config_yaml = Mcalendar::BUILT_IN_CONFIG_FILE
17
+ end
18
+
19
+ load_config(config_yaml)
20
+
21
+ end
22
+
23
+ def hash_key_to_sym(h)
24
+ Hash[h.map{|k, v| [k.to_s.to_sym, v]}]
25
+ end
26
+
27
+ def load_config(file)
28
+ @config = YAML.load(File.read(file))
29
+ holidays_schedule
30
+ anniversaries_schedule
31
+ end
32
+
33
+ def holidays_schedule
34
+ @options[:holiday] = hash_key_to_sym(@config["holiday"]) if @config["holiday"]
35
+ end
36
+
37
+ def anniversaries_schedule
38
+ @options[:anniversary] = hash_key_to_sym(@config["anniversary"]) if @config["anniversary"]
39
+ end
40
+
41
+ def parse(argv)
6
42
  parser = OptionParser.new do |o|
7
43
  o.on_head("-v", "--version", "Show version") do |v|
8
- options[:version] = v
44
+ @options[:version] = v
9
45
  o.version = Mcalendar::VERSION
10
46
  puts o.version
11
47
  end
12
- o.on("-p", "--pdf", "output pdf") { |v| options[:pdf] = v }
13
- o.on("-n NAME", "--name=NAME", String, "output pdf name") { |v| options[:name] = v }
14
- o.on("-c", "--console", "output console") { |v| options[:console] = v }
48
+
49
+ o.on("-p", "--pdf", "output pdf") { |v| @options[:pdf] = v }
50
+
51
+ o.on("-n NAME", "--name=NAME", String, "output pdf name") { |v| @options[:name] = v }
52
+
53
+ o.on("-c", "--console", "output console") { |v| @options[:console] = v }
54
+
55
+ o.on("-f FILE", "--config=FILE", "Use YAML format file.") do |file|
56
+ load_config(file) if file and File.exist?(file)
57
+ end
58
+
59
+ o.on("-y", "--holidays", "Display holidays and anniversaries in YAML file") { |v| @options[:holidays] = v }
15
60
  end
16
61
 
17
62
  begin
18
63
  remained = parser.parse!(argv)
19
- rescue OptionParser::InvalidArgument => e
20
- abort e.message
21
64
  rescue OptionParser::MissingArgument => e
22
65
  case e.args
23
66
  when ["-n"], ["--name"]
24
- options[:name] = Mcalendar::DEFAULT_PDF_NAME
67
+ @options[:name] = Mcalendar::DEFAULT_PDF_NAME
25
68
  end
69
+ rescue OptionParser::ParseError => e
70
+ puts parser
71
+ abort e.message
26
72
  end
27
73
 
28
74
  begin
29
- d = Date.parse(remained.first)
75
+ @options[:date] = Date.parse(remained.first)
30
76
  rescue
31
- d = Date.today
77
+ @options[:date] = Date.today
32
78
  end
33
79
 
34
- { date: d, opt: options }
80
+ @options
35
81
  end
82
+
36
83
  end
37
84
  end
@@ -1,19 +1,19 @@
1
1
  module Mcalendar
2
2
  class OutputPdf < Prawn::Document
3
- include Mcalendar::Config
3
+ extend Forwardable
4
+ def_delegator :@calendar, :month_title
4
5
 
5
- def initialize(obj_calendar)
6
- @first_of_month = obj_calendar.first_of_month
7
- @end_of_month = obj_calendar.end_of_month
8
- @month_header = [[obj_calendar.month_title]]
9
- @day_of_week = [Mcalendar::DAY_OF_WEEK]
6
+ def initialize(calendar, schedule)
7
+ @calendar = calendar
8
+ @schedule = schedule
10
9
 
11
- @pdf_days = []
12
- days_information
13
- @pdf_days = days
14
- @calendar = @pdf_days.each_slice(7).map
15
- @day_height = @calendar.size > 5 ? 20 : 20
16
- @text_height = @calendar.size > 5 ? 30 : 40
10
+ @month_header = [[month_title]]
11
+ @day_of_week = [Mcalendar::DAY_OF_WEEK]
12
+
13
+
14
+ @weekly_schedule = @schedule.daily_schedule.each_slice(7).map
15
+ @day_height = @weekly_schedule.size > 5 ? 20 : 20
16
+ @text_height = @weekly_schedule.size > 5 ? 30 : 40
17
17
 
18
18
  super(page_size: 'A4', margin: 20)
19
19
  calendar_render
@@ -36,8 +36,8 @@ module Mcalendar
36
36
  end
37
37
  end
38
38
 
39
- def day_content
40
- @calendar.each do |c|
39
+ def days_schedule
40
+ @weekly_schedule.each do |c|
41
41
  row_day = c.map {|x| (x.class == Struct::ConfigDay) ? x.day : x}
42
42
  row_color = c.map {|x| (x.class == Struct::ConfigDay) ? x.day_color : :black}
43
43
  row_text = c.map do |x|
@@ -80,7 +80,7 @@ module Mcalendar
80
80
  stroke_bounds
81
81
  month_header
82
82
  week_header
83
- day_content
83
+ days_schedule
84
84
  end
85
85
  end
86
86
 
@@ -0,0 +1,90 @@
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
+ @date = @config_schedule[:date]
22
+
23
+ setup_schedule
24
+ end
25
+
26
+ def holidays_in_the_year(holidays)
27
+ holidays.map do |k,v|
28
+ year_of_key = Date.parse(k.to_s).year
29
+ "#{k}: #{v}" if year_of_key == Date.parse(@date.to_s).year
30
+ end.compact
31
+ end
32
+
33
+ def show_holidays
34
+ holidays_in_the_year(@holidays)
35
+ end
36
+
37
+ def show_anniversaries
38
+ holidays_in_the_year(@anniversaries)
39
+ end
40
+
41
+ def setup_schedule
42
+ days_basic
43
+ holidays_in_the_month
44
+ anniversaries_in_the_month
45
+ end
46
+
47
+ def days_basic
48
+ (first_of_month..end_of_month).each do |date|
49
+ d_sym = date.strftime("%Y%m%d").to_sym
50
+ @days_config[d_sym] = Config_day.new(date.day, :black, nil, nil)
51
+ end
52
+
53
+ @days_config
54
+ end
55
+
56
+ def holidays_in_the_month
57
+ y = format("%4d", first_of_month.year)
58
+ m = format("%02d", first_of_month.month)
59
+ regex = /#{y}#{m}\d\d/
60
+
61
+ @holidays.keys.grep(regex).each do |d|
62
+ @days_config[d].day = Date.parse(d.to_s).day
63
+ @days_config[d].day_color = :red
64
+ @days_config[d].holiday_text = @holidays[d]
65
+ end
66
+
67
+ @days_config
68
+ end
69
+
70
+ def anniversaries_in_the_month
71
+ y = format("%4d", first_of_month.year)
72
+ m = format("%02d", first_of_month.month)
73
+ regex = /#{y}#{m}\d\d/
74
+
75
+ @anniversaries.keys.grep(regex).each do |d|
76
+ @days_config[d].day = Date.parse(d.to_s).day
77
+ @days_config[d].anniversary_text = @anniversaries[d]
78
+ end
79
+
80
+ @days_config
81
+ end
82
+
83
+ def daily_schedule
84
+ daily = @days_config.each_value.map { |val| val }
85
+ first_of_month.wday.times { daily.unshift(" ") }
86
+ daily
87
+ end
88
+
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
- module Mcalendar
2
- VERSION = "0.3.7"
3
- end
1
+ module Mcalendar
2
+ VERSION = "0.5.3"
3
+ end
data/lib/mcalendar.rb CHANGED
@@ -1,12 +1,15 @@
1
- require 'date'
2
- require "prawn"
3
- require "prawn/table"
4
- require "optparse"
5
-
6
- require_relative 'mcalendar/calendar'
7
- require_relative 'mcalendar/command'
8
- require_relative 'mcalendar/config'
9
- require_relative 'mcalendar/holiday'
10
- require_relative 'mcalendar/options'
11
- require_relative 'mcalendar/output_pdf'
12
- require_relative 'mcalendar/version'
1
+ require 'date'
2
+ require "prawn"
3
+ require "prawn/table"
4
+ require "optparse"
5
+ require 'forwardable'
6
+ require "yaml"
7
+
8
+ require_relative 'mcalendar/calendar'
9
+ require_relative 'mcalendar/command'
10
+ require_relative 'mcalendar/config'
11
+ require_relative 'mcalendar/holiday'
12
+ require_relative 'mcalendar/options'
13
+ require_relative 'mcalendar/output_pdf'
14
+ require_relative 'mcalendar/schedule'
15
+ require_relative 'mcalendar/version'
data/mcalendar.gemspec CHANGED
@@ -1,31 +1,32 @@
1
- require_relative 'lib/mcalendar/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "mcalendar"
5
- spec.version = Mcalendar::VERSION
6
- spec.authors = ["icm7216"]
7
- spec.email = ["icm7216d@gmail.com"]
8
-
9
- spec.summary = %q{Ruby Monthly calendar}
10
- spec.description = %q{Ruby Monthly Calendar, Console and pdf}
11
- spec.homepage = "https://github.com/icm7216/mcalendar"
12
- spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
-
15
- # Specify which files should be added to the gem when it is released.
16
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_runtime_dependency "prawn"
25
- spec.add_runtime_dependency "prawn-table"
26
-
27
- spec.add_development_dependency "test-unit"
28
- spec.add_development_dependency "test-unit-rr"
29
- spec.add_development_dependency "prawn"
30
- spec.add_development_dependency "prawn-table"
31
- end
1
+ require_relative 'lib/mcalendar/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "mcalendar"
5
+ spec.version = Mcalendar::VERSION
6
+ spec.authors = ["icm7216"]
7
+ spec.email = ["icm7216d@gmail.com"]
8
+
9
+ spec.summary = %q{Ruby Monthly calendar}
10
+ spec.description = %q{Ruby Monthly Calendar, Console and pdf}
11
+ spec.homepage = "https://github.com/icm7216/mcalendar"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "prawn"
25
+ spec.add_runtime_dependency "prawn-table"
26
+
27
+ spec.add_development_dependency "test-unit"
28
+ spec.add_development_dependency "test-unit-rr"
29
+ spec.add_development_dependency "prawn"
30
+ spec.add_development_dependency "prawn-table"
31
+ spec.add_development_dependency "rake"
32
+ end
data/mcalendar.yml ADDED
@@ -0,0 +1,52 @@
1
+ # Japanese holidays in English
2
+ # https://www8.cao.go.jp/chosei/shukujitsu/gaiyou.html
3
+ # 2021 -> 2022
4
+
5
+ holiday:
6
+ # 2021
7
+ 20210101: New Year's Day
8
+ 20210111: Coming-of-age Day
9
+ 20210211: National Foundation Day
10
+ 20210223: Emperor's Birthday
11
+ 20210320: Vernal Equinox Day
12
+ 20210429: Showa Day
13
+ 20210503: Constitution Memorial Day
14
+ 20210504: Greenery Day
15
+ 20210505: Children's Day
16
+ 20210722: Marine Day
17
+ 20210723: Sports Day
18
+ 20210808: Mountain Day
19
+ 20210809: Substitute Holiday
20
+ 20210920: Respect for the Aged Day
21
+ 20210923: Autumnal Equinox Day
22
+ 20211103: Culture Day
23
+ 20211123: Labour Thanksgiving Day
24
+ # 2022
25
+ 20220101: New Year's Day
26
+ 20220110: Coming-of-age Day
27
+ 20220211: National Foundation Day
28
+ 20220223: Emperor's Birthday
29
+ 20220321: Vernal Equinox Day
30
+ 20220429: Showa Day
31
+ 20220503: Constitution Memorial Day
32
+ 20220504: Greenery Day
33
+ 20220505: Children's Day
34
+ 20220718: Marine Day
35
+ 20220811: Mountain Day
36
+ 20220919: Respect for the Aged Day
37
+ 20220923: Autumnal Equinox Day
38
+ 20221010: Sports Day
39
+ 20221103: Culture Day
40
+ 20221123: Labour Thanksgiving Day
41
+
42
+ anniversary:
43
+ # 2021
44
+ 20210224: Ruby's Birthday
45
+ 20210909: RubyKaigi Takeout 2021
46
+ 20210910: RubyKaigi Takeout 2021
47
+ 20210911: RubyKaigi Takeout 2021
48
+ # 2022
49
+ 20220224: Ruby's Birthday
50
+ # 2022xxxx: RubyKaigi
51
+ # 2022xxxx: RubyKaigi
52
+ # 2022xxxx: RubyKaigi
data/test-unit.yml ADDED
@@ -0,0 +1,12 @@
1
+ runner: console
2
+ console_options:
3
+ color_scheme: normal
4
+ color_schemes:
5
+ normal:
6
+ success:
7
+ name: green
8
+ bold: false
9
+ failure:
10
+ name: red
11
+ bold: true
12
+
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.3.7
4
+ version: 0.5.3
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-04 00:00:00.000000000 Z
11
+ date: 2022-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Ruby Monthly Calendar, Console and pdf
98
112
  email:
99
113
  - icm7216d@gmail.com
@@ -118,8 +132,11 @@ files:
118
132
  - lib/mcalendar/holiday.rb
119
133
  - lib/mcalendar/options.rb
120
134
  - lib/mcalendar/output_pdf.rb
135
+ - lib/mcalendar/schedule.rb
121
136
  - lib/mcalendar/version.rb
122
137
  - mcalendar.gemspec
138
+ - mcalendar.yml
139
+ - test-unit.yml
123
140
  homepage: https://github.com/icm7216/mcalendar
124
141
  licenses:
125
142
  - MIT