mcalendar 0.2.4 → 0.3.0
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/lib/mcalendar.rb +2 -1
- data/lib/mcalendar/calendar.rb +4 -6
- data/lib/mcalendar/config.rb +37 -0
- data/lib/mcalendar/holiday.rb +22 -0
- data/lib/mcalendar/output_pdf.rb +22 -7
- data/lib/mcalendar/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a619d15bdf7550215ac9ed848508a86ebac27ca5ddfb3c760f890c6e50f93cf
|
4
|
+
data.tar.gz: e76dc41e97df81ef0a473931202b59eaccb71c059b8fb3578c1073783e2e335d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2beaf4b682f708bc7ecf63fe41a6e4b1f77602df58c9be037525d33892e4d2d70b25bf52117c7024b9243c7844984ae902a78e61f68b08d2944755752b82577f
|
7
|
+
data.tar.gz: ed12bf433ad7fd82b132e976d1b765f032ca374960257c90578f48bcd97ab834f0b99c4f7b48f6b7fb728bfec6396c69b71fb32e9d881959fc8b8d35e48fe3a0
|
data/lib/mcalendar.rb
CHANGED
@@ -3,9 +3,10 @@ require "prawn"
|
|
3
3
|
require "prawn/table"
|
4
4
|
require "optparse"
|
5
5
|
|
6
|
-
require_relative 'mcalendar/config'
|
7
6
|
require_relative 'mcalendar/calendar'
|
8
7
|
require_relative 'mcalendar/command'
|
8
|
+
require_relative 'mcalendar/config'
|
9
|
+
require_relative 'mcalendar/holiday'
|
9
10
|
require_relative 'mcalendar/options'
|
10
11
|
require_relative 'mcalendar/output_pdf'
|
11
12
|
require_relative 'mcalendar/version'
|
data/lib/mcalendar/calendar.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
|
2
2
|
module Mcalendar
|
3
|
-
DEFAULT_PDF_NAME = "calendar.pdf"
|
4
|
-
DAY_OF_WEEK = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
|
5
3
|
|
6
4
|
class Calendar
|
7
|
-
attr_reader :pdf_name, :month_title, :days
|
5
|
+
attr_reader :pdf_name, :month_title, :days, :first_of_month, :end_of_month
|
8
6
|
|
9
7
|
def initialize(year, month, pdf_name)
|
10
|
-
first_of_month = Date.new(year, month, 1)
|
11
|
-
end_of_month = Date.new(year, month, -1)
|
8
|
+
@first_of_month = Date.new(year, month, 1)
|
9
|
+
@end_of_month = Date.new(year, month, -1)
|
12
10
|
@days = (1..end_of_month.day).map {|m| "%2d" % m}
|
13
11
|
first_of_month.wday.times {@days.unshift(" ")}
|
14
12
|
@month_title = first_of_month.strftime("%B %Y")
|
@@ -17,7 +15,7 @@ module Mcalendar
|
|
17
15
|
|
18
16
|
def set_pdf_name(name)
|
19
17
|
if name.nil? || name.empty?
|
20
|
-
@pdf_name = Mcalendar::DEFAULT_PDF_NAME
|
18
|
+
@pdf_name = Mcalendar::Config::DEFAULT_PDF_NAME
|
21
19
|
else
|
22
20
|
@pdf_name = name
|
23
21
|
end
|
data/lib/mcalendar/config.rb
CHANGED
@@ -21,6 +21,43 @@ module Mcalendar
|
|
21
21
|
}
|
22
22
|
|
23
23
|
DAY_OF_WEEK = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
|
24
|
+
DEFAULT_PDF_NAME = "calendar.pdf"
|
25
|
+
|
26
|
+
Config_day = Struct.new("ConfigDay", :day, :text, :color)
|
27
|
+
|
28
|
+
def self.days_information(obj_calendar)
|
29
|
+
@first_of_month = obj_calendar.first_of_month
|
30
|
+
@end_of_month = obj_calendar.end_of_month
|
31
|
+
|
32
|
+
@days_config = Hash.new(nil)
|
33
|
+
days_basic
|
34
|
+
holiday
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.days_basic
|
38
|
+
(@first_of_month..@end_of_month).each do |date|
|
39
|
+
d_sym = date.strftime("%Y%m%d").to_sym
|
40
|
+
@days_config[d_sym] = Config_day.new(date.day, " ", :black)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.holiday
|
45
|
+
y = "%4d" % @first_of_month.year
|
46
|
+
m = "%02d" % @first_of_month.month
|
47
|
+
regex = /#{y}#{m}\d\d/
|
24
48
|
|
49
|
+
Mcalendar::HOLIDAY.keys.grep(regex).each do |d|
|
50
|
+
@days_config[d].day = Date.parse(d.to_s).day
|
51
|
+
@days_config[d].text = Mcalendar::HOLIDAY[d]
|
52
|
+
@days_config[d].color = :red
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.days
|
57
|
+
pdf_days = @days_config.each_value.map {|val| val}
|
58
|
+
@first_of_month.wday.times {pdf_days.unshift(" ")}
|
59
|
+
pdf_days
|
60
|
+
end
|
61
|
+
|
25
62
|
end
|
26
63
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mcalendar
|
2
|
+
HOLIDAY = {
|
3
|
+
"20200101": "New Year's Day",
|
4
|
+
"20200113": "Coming-of-age Day",
|
5
|
+
"20200211": "National Foundation Day",
|
6
|
+
"20200223": "Emperor's Birthday",
|
7
|
+
"20200224": "Substitute Holiday",
|
8
|
+
"20200320": "Vernal Equinox Day",
|
9
|
+
"20200429": "Showa Day",
|
10
|
+
"20200503": "Constitution Memorial Day",
|
11
|
+
"20200504": "Greenery Day",
|
12
|
+
"20200505": "Children's Day",
|
13
|
+
"20200506": "Substitute Holiday",
|
14
|
+
"20200723": "Marine Day",
|
15
|
+
"20200724": "Sports Day",
|
16
|
+
"20200810": "Mountain Day",
|
17
|
+
"20200921": "Respect for the Aged Day",
|
18
|
+
"20200922": "Autumnal Equinox Day",
|
19
|
+
"20201103": "Culture Day",
|
20
|
+
"20201123": "Labour Thanksgiving Day"
|
21
|
+
}
|
22
|
+
end
|
data/lib/mcalendar/output_pdf.rb
CHANGED
@@ -4,7 +4,11 @@ module Mcalendar
|
|
4
4
|
def initialize(obj_calendar)
|
5
5
|
@month_header = [[obj_calendar.month_title]]
|
6
6
|
@day_of_week = [Mcalendar::Config::DAY_OF_WEEK]
|
7
|
-
|
7
|
+
|
8
|
+
@pdf_days = []
|
9
|
+
Mcalendar::Config::days_information(obj_calendar)
|
10
|
+
@pdf_days = Mcalendar::Config::days
|
11
|
+
@calendar = @pdf_days.each_slice(7).map
|
8
12
|
@cell_height = @calendar.size > 5 ? 50 : 60
|
9
13
|
|
10
14
|
super(page_size: 'A4', margin: 20)
|
@@ -30,22 +34,33 @@ module Mcalendar
|
|
30
34
|
|
31
35
|
def day_content
|
32
36
|
@calendar.each do |c|
|
33
|
-
|
37
|
+
row_day = c.map {|x| (x.class == Struct::ConfigDay) ? x.day : x}
|
38
|
+
row_color = c.map {|x| (x.class == Struct::ConfigDay) ? x.color : :black}
|
39
|
+
row_text = c.map {|x| (x.class == Struct::ConfigDay) ? x.text : x}
|
40
|
+
|
41
|
+
table([row_day], cell_style: {height: @cell_height / 2}) do
|
34
42
|
cells.style(width: 79, align: :center, size: 19)
|
35
43
|
row(0).borders = [:top, :left, :right]
|
36
|
-
row(0).padding_top =
|
44
|
+
row(0).padding_top = 5
|
37
45
|
row(0).padding_bottom = 0
|
38
|
-
|
46
|
+
row_color.each_with_index do |color, index|
|
47
|
+
rows(0).columns(index).text_color = Mcalendar::Config::COLOR[color]
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
|
-
|
42
|
-
table([dummy_text], cell_style: {height: @cell_height / 2}) do
|
51
|
+
table([row_text], cell_style: {height: @cell_height / 2}) do
|
43
52
|
cells.style(width: 79, align: :center, size: 10)
|
44
53
|
row(0).style = {overflow: :shrink_to_fit}
|
45
54
|
row(0).borders = [:bottom, :left, :right]
|
46
|
-
row(0).padding_top =
|
55
|
+
row(0).padding_top = 1
|
47
56
|
row(0).padding_bottom = 0
|
57
|
+
row(0).padding_left = 0
|
58
|
+
row(0).padding_right = 0
|
59
|
+
row_color.each_with_index do |color, index|
|
60
|
+
rows(0).columns(index).text_color = Mcalendar::Config::COLOR[color]
|
61
|
+
end
|
48
62
|
end
|
63
|
+
|
49
64
|
end
|
50
65
|
end
|
51
66
|
|
data/lib/mcalendar/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcalendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- icm7216
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/mcalendar/calendar.rb
|
88
88
|
- lib/mcalendar/command.rb
|
89
89
|
- lib/mcalendar/config.rb
|
90
|
+
- lib/mcalendar/holiday.rb
|
90
91
|
- lib/mcalendar/options.rb
|
91
92
|
- lib/mcalendar/output_pdf.rb
|
92
93
|
- lib/mcalendar/version.rb
|