mcalendar 0.3.3 → 0.3.4

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: 3d49258fa85dc25cba82e52375c0d9652863a5b5c432b11de5d2772ab5cb95eb
4
- data.tar.gz: ba46bf414da324ceff275435f1a786fe51c44c8638719b3c9543d1ad6389e6e7
3
+ metadata.gz: 21ef82a6c59eecbb2f6352fcdd3c07319ba97b7c0171c3e0f62acd2af9cf2b69
4
+ data.tar.gz: a0964b22fc234f1c30e4ff849891cc9e87ce4df0d0fd1b319fb7b7ab33371f38
5
5
  SHA512:
6
- metadata.gz: 80c9b282b8e0f427f23facda279b0d626100d02b26077c2c49ff3792e2ee1beb60de9555b356b508ce8b86e852c7bcdae1719d4271c5b0e1ca2a01df20f62920
7
- data.tar.gz: 213447a21b7a77c6d196f566da8b48d259ba918b82f8ccc162da887f173b08e7b669eba2ac1e9cb76bb40620e7d3413c52a1058fd30d19a526cf37f03a7c6cab
6
+ metadata.gz: 937ead03075cbc8f91df5051cb1b4ba8c20f64bcad713f213c328e3a7dc285aa3404fc44a2bb5803fe49811456844020b12366c60a8c7a228ac43ce07fa3b0c2
7
+ data.tar.gz: 3d2082a57b49dce4647546899083832d7b9a8e7b754f0aa0a113c5a5142c8cc93f796510f96ba758bd76d6ffbc058a7814b5d58ddca665761e504707fc3f6246
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(" ")]}
@@ -1,33 +1,39 @@
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
+ }
22
21
 
23
- DAY_OF_WEEK = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
24
- DEFAULT_PDF_NAME = "calendar.pdf"
22
+ DAY_OF_WEEK = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
23
+ DEFAULT_PDF_NAME = "calendar.pdf"
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)
33
39
  days_basic
@@ -35,42 +41,37 @@ module Mcalendar
35
41
  anniversary
36
42
  end
37
43
 
38
- def self.days_basic
44
+ def days_basic
39
45
  (@first_of_month..@end_of_month).each do |date|
40
46
  d_sym = date.strftime("%Y%m%d").to_sym
41
- @days_config[d_sym] = Config_day.new(date.day, " ", :black)
47
+ @days_config[d_sym] = Config_day.new(date.day, :black, nil, nil)
42
48
  end
43
49
  end
44
50
 
45
- def self.holiday
51
+ def holiday
46
52
  y = "%4d" % @first_of_month.year
47
53
  m = "%02d" % @first_of_month.month
48
54
  regex = /#{y}#{m}\d\d/
49
55
 
50
56
  Mcalendar::HOLIDAY.keys.grep(regex).each do |d|
51
57
  @days_config[d].day = Date.parse(d.to_s).day
52
- @days_config[d].text = Mcalendar::HOLIDAY[d]
53
- @days_config[d].color = :red
58
+ @days_config[d].day_color = :red
59
+ @days_config[d].holiday_text = Mcalendar::HOLIDAY[d]
54
60
  end
55
61
  end
56
62
 
57
- def self.anniversary
63
+ def anniversary
58
64
  y = "%4d" % @first_of_month.year
59
65
  m = "%02d" % @first_of_month.month
60
66
  regex = /#{y}#{m}\d\d/
61
67
 
62
68
  Mcalendar::ANNIVERSARY.keys.grep(regex).each do |d|
63
69
  @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
70
+ @days_config[d].anniversary_text = Mcalendar::ANNIVERSARY[d]
70
71
  end
71
72
  end
72
73
 
73
- def self.days
74
+ def days
74
75
  pdf_days = @days_config.each_value.map {|val| val}
75
76
  @first_of_month.wday.times {pdf_days.unshift(" ")}
76
77
  pdf_days
@@ -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.4"
3
3
  end
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.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - icm7216
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit