mcalendar 0.3.3 → 0.3.7

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: 3d49258fa85dc25cba82e52375c0d9652863a5b5c432b11de5d2772ab5cb95eb
4
- data.tar.gz: ba46bf414da324ceff275435f1a786fe51c44c8638719b3c9543d1ad6389e6e7
3
+ metadata.gz: 1c37d4882b2dcea8a3df4b7e8802b319ccbfd1f650fe2fc90e6fb6fafa9919d3
4
+ data.tar.gz: f6005e4ea03becf4302e45490dcd4a0f00230d6db48d1bec4d6411f7d45c9560
5
5
  SHA512:
6
- metadata.gz: 80c9b282b8e0f427f23facda279b0d626100d02b26077c2c49ff3792e2ee1beb60de9555b356b508ce8b86e852c7bcdae1719d4271c5b0e1ca2a01df20f62920
7
- data.tar.gz: 213447a21b7a77c6d196f566da8b48d259ba918b82f8ccc162da887f173b08e7b669eba2ac1e9cb76bb40620e7d3413c52a1058fd30d19a526cf37f03a7c6cab
6
+ metadata.gz: '093c36d9b6ccfc75fe69e9c7fe4a406202e24c8592738f0b572f26dfe51802beadee078cfd84e32d4a2ee197406d1b2a97acb9b08e47de98efd1a3efd1f1ccb7'
7
+ data.tar.gz: ca679323931aaa7cdf0803c2a386b15c23f20d2ecf0902769f4e7e2a770ea5fb8124c1eada288e0847e4dbaaf92045b3a248060cef24ed37828a9cdd7f188690
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /Gemfile.lock
10
10
  pdf/*.pdf
11
11
  *.pdf
12
+ /.vscode/
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  # Mcalendar [![Gem Version](https://badge.fury.io/rb/mcalendar.svg)](https://badge.fury.io/rb/mcalendar)
3
3
 
4
- Ruby monthly calendar, console and pdf.
5
-
4
+ Ruby monthly calendar, console and pdf.
5
+ This calendar includes Japanese holidays.
6
6
 
7
7
  ## Installation
8
8
 
@@ -15,14 +15,14 @@ module Mcalendar
15
15
 
16
16
  def set_pdf_name(name)
17
17
  if name.nil? || name.empty?
18
- @pdf_name = Mcalendar::Config::DEFAULT_PDF_NAME
18
+ @pdf_name = Mcalendar::DEFAULT_PDF_NAME
19
19
  else
20
20
  @pdf_name = name
21
21
  end
22
22
  end
23
23
 
24
24
  def to_s
25
- week_header = Mcalendar::Config::DAY_OF_WEEK.join(" ")
25
+ week_header = Mcalendar::DAY_OF_WEEK.join(" ")
26
26
  month_header = @month_title.center(week_header.size).rstrip
27
27
  calendar = [[week_header]]
28
28
  @days.each_slice(7) {|x| calendar << [x.join(" ")]}
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Mcalendar
4
4
  class Command
5
-
6
5
  def self.run(argv)
7
6
  new(argv).execute
8
7
  end
@@ -12,12 +11,12 @@ module Mcalendar
12
11
  end
13
12
 
14
13
  def execute
15
-
16
14
  options = Mcalendar::Options.parse(@argv)
17
15
  date = options[:date]
18
16
  console = options[:opt][:console]
19
17
  pdf = options[:opt][:pdf]
20
18
  pdf_name = options[:opt][:name]
19
+ version = options[:opt][:version]
21
20
  calendar = Mcalendar::Calendar.new(date.year, date.month, pdf_name)
22
21
 
23
22
  # output calendar
@@ -25,11 +24,10 @@ module Mcalendar
25
24
  calendar.pdf if pdf
26
25
 
27
26
  # both outputs if no options
28
- if console.nil? && pdf.nil?
27
+ if console.nil? && pdf.nil? && version.nil?
29
28
  calendar.display
30
29
  calendar.pdf
31
30
  end
32
-
33
31
  end
34
32
  end
35
33
  end
@@ -1,80 +1,86 @@
1
1
  module Mcalendar
2
- module Config
3
- COLOR = {
4
- white: "FFFFFF",
5
- silver: "C0C0C0",
6
- gray: "808080",
7
- black: "000000",
8
- red: "FF0000",
9
- maroon: "800000",
10
- yellow: "FFFF00",
11
- olive: "808000",
12
- lime: "00FF00",
13
- green: "008000",
14
- aqua: "00FFFF",
15
- teal: "008080",
16
- blue: "0000FF",
17
- navy: "000080",
18
- fuchsia: "FF00FF",
19
- purple: "800080",
20
- orange: "FFA500",
21
- }
2
+ COLOR = {
3
+ white: "FFFFFF",
4
+ silver: "C0C0C0",
5
+ gray: "808080",
6
+ black: "000000",
7
+ red: "FF0000",
8
+ maroon: "800000",
9
+ yellow: "FFFF00",
10
+ olive: "808000",
11
+ lime: "00FF00",
12
+ green: "008000",
13
+ aqua: "00FFFF",
14
+ teal: "008080",
15
+ blue: "0000FF",
16
+ navy: "000080",
17
+ fuchsia: "FF00FF",
18
+ purple: "800080",
19
+ orange: "FFA500",
20
+ }.freeze
22
21
 
23
- DAY_OF_WEEK = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
24
- DEFAULT_PDF_NAME = "calendar.pdf"
22
+ DAY_OF_WEEK = %w[Sun Mon Tue Wed Thu Fri Sat].freeze
23
+ DEFAULT_PDF_NAME = "calendar.pdf".freeze
25
24
 
26
- Config_day = Struct.new("ConfigDay", :day, :text, :color)
25
+ Config_day = Struct.new(
26
+ "ConfigDay",
27
+ :day,
28
+ :day_color,
29
+ :holiday_text,
30
+ :anniversary_text
31
+ )
27
32
 
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
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
31
37
 
32
38
  @days_config = Hash.new(nil)
39
+ holiday_description_language
33
40
  days_basic
34
41
  holiday
35
42
  anniversary
36
43
  end
37
44
 
38
- def self.days_basic
45
+ def days_basic
39
46
  (@first_of_month..@end_of_month).each do |date|
40
47
  d_sym = date.strftime("%Y%m%d").to_sym
41
- @days_config[d_sym] = Config_day.new(date.day, " ", :black)
48
+ @days_config[d_sym] = Config_day.new(date.day, :black, nil, nil)
42
49
  end
43
50
  end
44
51
 
45
- def self.holiday
46
- y = "%4d" % @first_of_month.year
47
- m = "%02d" % @first_of_month.month
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)
48
60
  regex = /#{y}#{m}\d\d/
49
-
61
+
50
62
  Mcalendar::HOLIDAY.keys.grep(regex).each do |d|
51
63
  @days_config[d].day = Date.parse(d.to_s).day
52
- @days_config[d].text = Mcalendar::HOLIDAY[d]
53
- @days_config[d].color = :red
64
+ @days_config[d].day_color = :red
65
+ @days_config[d].holiday_text = Mcalendar::HOLIDAY[d]
54
66
  end
55
67
  end
56
68
 
57
- def self.anniversary
58
- y = "%4d" % @first_of_month.year
59
- m = "%02d" % @first_of_month.month
69
+ def anniversary
70
+ y = format("%4d", @first_of_month.year)
71
+ m = format("%02d", @first_of_month.month)
60
72
  regex = /#{y}#{m}\d\d/
61
-
73
+
62
74
  Mcalendar::ANNIVERSARY.keys.grep(regex).each do |d|
63
75
  @days_config[d].day = Date.parse(d.to_s).day
64
- if @days_config[d].text.size > 1
65
- @days_config[d].text += (", " + Mcalendar::ANNIVERSARY[d])
66
- else
67
- @days_config[d].text += Mcalendar::ANNIVERSARY[d]
68
- end
69
- @days_config[d].color = :black if @days_config[d].color != :red
76
+ @days_config[d].anniversary_text = Mcalendar::ANNIVERSARY[d]
70
77
  end
71
78
  end
72
79
 
73
- def self.days
74
- pdf_days = @days_config.each_value.map {|val| val}
75
- @first_of_month.wday.times {pdf_days.unshift(" ")}
80
+ def days
81
+ pdf_days = @days_config.each_value.map { |val| val }
82
+ @first_of_month.wday.times { pdf_days.unshift(" ") }
76
83
  pdf_days
77
84
  end
78
-
79
85
  end
80
- end
86
+ end
@@ -1,31 +1,63 @@
1
1
  module Mcalendar
2
+ module JA
3
+ # Japanese holidays in Japanese
4
+ 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": "勤労感謝の日",
23
+ }.freeze
2
24
 
3
- # Japanese holidays
4
- HOLIDAY = {
5
- "20200101": "New Year's Day",
6
- "20200113": "Coming-of-age Day",
7
- "20200211": "National Foundation Day",
8
- "20200223": "Emperor's Birthday",
9
- "20200224": "Substitute Holiday",
10
- "20200320": "Vernal Equinox Day",
11
- "20200429": "Showa Day",
12
- "20200503": "Constitution Memorial Day",
13
- "20200504": "Greenery Day",
14
- "20200505": "Children's Day",
15
- "20200506": "Substitute Holiday",
16
- "20200723": "Marine Day",
17
- "20200724": "Sports Day",
18
- "20200810": "Mountain Day",
19
- "20200921": "Respect for the Aged Day",
20
- "20200922": "Autumnal Equinox Day",
21
- "20201103": "Culture Day",
22
- "20201123": "Labour Thanksgiving Day"
23
- }
25
+ ANNIVERSARY = {
26
+ "20200224": "Rubyの誕生日",
27
+ "20200903": "RubyKaigi 2020 Nagano",
28
+ "20200904": "RubyKaigi 2020 Nagano",
29
+ "20200905": "RubyKaigi 2020 Nagano",
30
+ }.freeze
31
+ end
24
32
 
25
- ANNIVERSARY = {
26
- "20200224": "Ruby's Birthday",
27
- "20200409": "RubyKaigi 2020 Nagano",
28
- "20200410": "RubyKaigi 2020 Nagano",
29
- "20200411": "RubyKaigi 2020 Nagano"
30
- }
33
+ module EN
34
+ # Japanese holidays in English
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",
54
+ }.freeze
55
+
56
+ ANNIVERSARY = {
57
+ "20200224": "Ruby's Birthday",
58
+ "20200903": "RubyKaigi 2020 Nagano",
59
+ "20200904": "RubyKaigi 2020 Nagano",
60
+ "20200905": "RubyKaigi 2020 Nagano",
61
+ }.freeze
62
+ end
31
63
  end
@@ -1,17 +1,17 @@
1
1
  module Mcalendar
2
2
  module Options
3
-
4
3
  def self.parse(argv)
5
4
  options = {}
6
5
 
7
6
  parser = OptionParser.new do |o|
8
- o.on_head('-v', '--version', 'Show version') do
7
+ o.on_head("-v", "--version", "Show version") do |v|
8
+ options[:version] = v
9
9
  o.version = Mcalendar::VERSION
10
10
  puts o.version
11
11
  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}
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 }
15
15
  end
16
16
 
17
17
  begin
@@ -24,14 +24,14 @@ module Mcalendar
24
24
  options[:name] = Mcalendar::DEFAULT_PDF_NAME
25
25
  end
26
26
  end
27
-
27
+
28
28
  begin
29
29
  d = Date.parse(remained.first)
30
30
  rescue
31
31
  d = Date.today
32
32
  end
33
33
 
34
- {date: d, opt: options}
34
+ { date: d, opt: options }
35
35
  end
36
36
  end
37
37
  end
@@ -1,13 +1,16 @@
1
1
  module Mcalendar
2
2
  class OutputPdf < Prawn::Document
3
+ include Mcalendar::Config
3
4
 
4
5
  def initialize(obj_calendar)
6
+ @first_of_month = obj_calendar.first_of_month
7
+ @end_of_month = obj_calendar.end_of_month
5
8
  @month_header = [[obj_calendar.month_title]]
6
- @day_of_week = [Mcalendar::Config::DAY_OF_WEEK]
9
+ @day_of_week = [Mcalendar::DAY_OF_WEEK]
7
10
 
8
11
  @pdf_days = []
9
- Mcalendar::Config::days_information(obj_calendar)
10
- @pdf_days = Mcalendar::Config::days
12
+ days_information
13
+ @pdf_days = days
11
14
  @calendar = @pdf_days.each_slice(7).map
12
15
  @day_height = @calendar.size > 5 ? 20 : 20
13
16
  @text_height = @calendar.size > 5 ? 30 : 40
@@ -29,15 +32,24 @@ module Mcalendar
29
32
  cells.style(width: 79, height: 40, align: :center, size: 19)
30
33
  row(0).padding_top = 10
31
34
  row(0).padding_bottom = 0
32
- cells[0, 0].text_color = Mcalendar::Config::COLOR[:red]
35
+ cells[0, 0].text_color = Mcalendar::COLOR[:red]
33
36
  end
34
37
  end
35
38
 
36
39
  def day_content
37
40
  @calendar.each do |c|
38
41
  row_day = c.map {|x| (x.class == Struct::ConfigDay) ? x.day : x}
39
- row_color = c.map {|x| (x.class == Struct::ConfigDay) ? x.color : :black}
40
- row_text = c.map {|x| (x.class == Struct::ConfigDay) ? x.text : x}
42
+ row_color = c.map {|x| (x.class == Struct::ConfigDay) ? x.day_color : :black}
43
+ row_text = c.map do |x|
44
+ str = ""
45
+ if x.class == Struct::ConfigDay
46
+ holiday_str = %Q[<color rgb="#{Mcalendar::COLOR[:red]}">#{x.holiday_text}</color>\n]
47
+ anniversary_str = %Q[<color rgb="#{Mcalendar::COLOR[:green]}">#{x.anniversary_text}</color>]
48
+ str += holiday_str if x.holiday_text
49
+ str += anniversary_str if x.anniversary_text
50
+ end
51
+ str
52
+ end
41
53
 
42
54
  table([row_day], cell_style: {height: @day_height}) do
43
55
  cells.style(width: 79, align: :center, size: 19)
@@ -45,23 +57,19 @@ module Mcalendar
45
57
  row(0).padding_top = 2
46
58
  row(0).padding_bottom = 0
47
59
  row_color.each_with_index do |color, index|
48
- rows(0).columns(index).text_color = Mcalendar::Config::COLOR[color]
60
+ rows(0).columns(index).text_color = Mcalendar::COLOR[color]
49
61
  end
50
- column(0).map {|col| col.text_color = Mcalendar::Config::COLOR[:red]}
62
+ column(0).map {|col| col.text_color = Mcalendar::COLOR[:red]}
51
63
  end
52
64
 
53
65
  table([row_text], cell_style: {height: @text_height}) do
54
- cells.style(width: 79, align: :center, size: 8, overflow: :shrink_to_fit)
66
+ cells.style(width: 79, align: :center, size: 8, overflow: :shrink_to_fit, inline_format: true)
55
67
  row(0).borders = [:bottom, :left, :right]
56
68
  row(0).padding_top = 0
57
69
  row(0).padding_bottom = 0
58
70
  row(0).padding_left = 0
59
71
  row(0).padding_right = 0
60
- row_color.each_with_index do |color, index|
61
- rows(0).columns(index).text_color = Mcalendar::Config::COLOR[color]
62
- end
63
72
  end
64
-
65
73
  end
66
74
  end
67
75
 
@@ -1,3 +1,3 @@
1
1
  module Mcalendar
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.7"
3
3
  end
data/mcalendar.gemspec CHANGED
@@ -21,6 +21,9 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
+ spec.add_runtime_dependency "prawn"
25
+ spec.add_runtime_dependency "prawn-table"
26
+
24
27
  spec.add_development_dependency "test-unit"
25
28
  spec.add_development_dependency "test-unit-rr"
26
29
  spec.add_development_dependency "prawn"
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.3
4
+ version: 0.3.7
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-01-17 00:00:00.000000000 Z
11
+ date: 2021-09-04 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
@@ -96,7 +124,7 @@ homepage: https://github.com/icm7216/mcalendar
96
124
  licenses:
97
125
  - MIT
98
126
  metadata: {}
99
- post_install_message:
127
+ post_install_message:
100
128
  rdoc_options: []
101
129
  require_paths:
102
130
  - lib
@@ -111,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
139
  - !ruby/object:Gem::Version
112
140
  version: '0'
113
141
  requirements: []
114
- rubygems_version: 3.0.6
115
- signing_key:
142
+ rubygems_version: 3.2.17
143
+ signing_key:
116
144
  specification_version: 4
117
145
  summary: Ruby Monthly calendar
118
146
  test_files: []