mcalendar 0.3.5 → 0.5.1

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: 27619fc0c5bfa245496da8f7c40af714931a96274b6f3eacbd383cf97a749aef
4
- data.tar.gz: 45cbfb1b5e59b75c57b50889d82948401b9c80d8037ba5d7da59964020baf78e
3
+ metadata.gz: 106df652910d9257dddfa3814af1ab493c2ead746ed454c94ce4aa9950014f16
4
+ data.tar.gz: 6889c7be1874699ac9c86bd96ee7e48f1d61a566c90a78dfb2f398163e86dcda
5
5
  SHA512:
6
- metadata.gz: 668ed5dda0d31695fe02b2b8946e858cf10b516a9bbc6317eacfd6f8e0d1d972a262ceb787d02a5b2fc8c4ce8c25b34309786f7980fcee02e8efbee87dc8c752
7
- data.tar.gz: 9871a3699694fde7f6d8f1bcab59328620403f86744bd15c00fd4dd25f1adb8bfc13602f6b2e5e3ac4efaa8c15cf33b92abf5f3881687cfed981f7f72a9dc990
6
+ metadata.gz: 953e8b02928a44b6129fc716858aceaf0d29288bd473b3f2e9e2e6dd2a3f7a8276fc1948e403840acb7640b83a68e4f733100c93d2fdc114843c33412823e629
7
+ data.tar.gz: 027ba073a3567099bf0f18378726925754097826ea8066c1c99b1776e87e90b816f9f6fc9af1cf03b41b1656ade0dc61c1bc2cfbe5e54fb4ffca8680d40d7801
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 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,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
- Config_day = Struct.new(
26
- "ConfigDay",
27
- :day,
28
- :day_color,
29
- :holiday_text,
30
- :anniversary_text
31
- )
25
+ DEFAULT_CONFIG_FILE = "mcalendar.yml".freeze
32
26
 
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
86
27
  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
- "20200409": "RubyKaigi 2020 Nagano",
28
- "20200410": "RubyKaigi 2020 Nagano",
29
- "20200411": "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
- "20200409": "RubyKaigi 2020 Nagano",
59
- "20200410": "RubyKaigi 2020 Nagano",
60
- "20200411": "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,17 +1,59 @@
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 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
- 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 }
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
- d = Date.parse(remained.first)
71
+ @options[:date] = Date.parse(remained.first)
30
72
  rescue
31
- d = Date.today
73
+ @options[:date] = Date.today
32
74
  end
33
75
 
34
- { date: d, opt: options }
76
+ @options
35
77
  end
78
+
36
79
  end
37
80
  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,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
@@ -1,3 +1,3 @@
1
- module Mcalendar
2
- VERSION = "0.3.5"
3
- end
1
+ module Mcalendar
2
+ VERSION = "0.5.1"
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,28 +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_development_dependency "test-unit"
25
- spec.add_development_dependency "test-unit-rr"
26
- spec.add_development_dependency "prawn"
27
- spec.add_development_dependency "prawn-table"
28
- 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,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
@@ -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,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mcalendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - icm7216
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-10 00:00:00.000000000 Z
11
+ date: 2021-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prawn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: prawn-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: test-unit
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +94,20 @@ dependencies:
66
94
  - - ">="
67
95
  - !ruby/object:Gem::Version
68
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'
69
111
  description: Ruby Monthly Calendar, Console and pdf
70
112
  email:
71
113
  - icm7216d@gmail.com
@@ -90,13 +132,16 @@ files:
90
132
  - lib/mcalendar/holiday.rb
91
133
  - lib/mcalendar/options.rb
92
134
  - lib/mcalendar/output_pdf.rb
135
+ - lib/mcalendar/schedule.rb
93
136
  - lib/mcalendar/version.rb
94
137
  - mcalendar.gemspec
138
+ - mcalendar.yml
139
+ - test-unit.yml
95
140
  homepage: https://github.com/icm7216/mcalendar
96
141
  licenses:
97
142
  - MIT
98
143
  metadata: {}
99
- post_install_message:
144
+ post_install_message:
100
145
  rdoc_options: []
101
146
  require_paths:
102
147
  - lib
@@ -111,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
156
  - !ruby/object:Gem::Version
112
157
  version: '0'
113
158
  requirements: []
114
- rubygems_version: 3.0.6
115
- signing_key:
159
+ rubygems_version: 3.2.17
160
+ signing_key:
116
161
  specification_version: 4
117
162
  summary: Ruby Monthly calendar
118
163
  test_files: []