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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4f1a0686f0df1be91433adbdde9d74b9be99d2f27604e22bb1013594e20628e
4
- data.tar.gz: c9a3f6121b369d8f2b47d235a39e321fb20365c1e4eb1564dc712cc96e6e6ad1
3
+ metadata.gz: 2a619d15bdf7550215ac9ed848508a86ebac27ca5ddfb3c760f890c6e50f93cf
4
+ data.tar.gz: e76dc41e97df81ef0a473931202b59eaccb71c059b8fb3578c1073783e2e335d
5
5
  SHA512:
6
- metadata.gz: 2c32d50df9618cb81a32e0f38abe8f0fa2fc7d15f0925d3ec737089d549920475630eb999b3e894e4578640e31f7da8db7a1736b8b6e7239a879e15a3ed842dd
7
- data.tar.gz: c9fb9883a4295a4066c841a589c65eba589a7ba89f5002975d5e85f00ccc8ce6fcec8188928945cfafe47ebf1476cf8d5603550d26d3effe27a7746991bd0d24
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'
@@ -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
@@ -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
@@ -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
- @calendar = obj_calendar.days.each_slice(7).map
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
- table([c], cell_style: {height: @cell_height / 2}) do
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 = 10
44
+ row(0).padding_top = 5
37
45
  row(0).padding_bottom = 0
38
- column(0).map {|c| c.text_color = Mcalendar::Config::COLOR[:red]}
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
- dummy_text = [""] * c.size
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 = 2
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
 
@@ -1,3 +1,3 @@
1
1
  module Mcalendar
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
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.2.4
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