mcalendar 0.2.0 → 0.2.1

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: b957b8968e85884abff40ef75462a3061a99fe97d057f8a80c5360a8f1ba11a4
4
- data.tar.gz: 508e4d57573f0bc0f0d44634553fe465cdab91efe94138c8385398d39fbf1e68
3
+ metadata.gz: 12d1ccf31150634c56cc06e9da682bc4cfcac632e8b84417016daba633162434
4
+ data.tar.gz: fa7418fb37a87aefe0d40d55dc309110eaa289a77f57aaf86c6395b92f44011b
5
5
  SHA512:
6
- metadata.gz: 7ec173986099a1c9d4070ccdb424b05093e5b2d70d54831595a6968d6ab7a08c7fa43b684d42986b00135c2455e7ad38d83f9b71ca36efca409f2a7a69e33aef
7
- data.tar.gz: 5903ccb62a28c78ff60deb53635d28e8b2c6e401ca8a0f5d471c02b54773da584b3c335679923e20816e14beb8e14630e99ef1e479e930832113316363588770
6
+ metadata.gz: 68922119c2ebe0ee50d2874270c382834178e119f72489ab441d504fcf9cd57876aad8ab4dd1ac8962a74a5cd1c5ce275ae4c84c1873e3b36f8e345689ff2e75
7
+ data.tar.gz: 69ff48ccb4793f99113d7cc4cd3ee97f2dabab2d0f4175d42eddeb272187bda99c370ff97cbe89abc62b1a20582bc482d2c47be295eb7996a86c5e3e115dde67
@@ -1,16 +1,18 @@
1
1
 
2
2
  module Mcalendar
3
3
  DEFAULT_PDF_NAME = "calendar.pdf"
4
+ DAY_OF_WEEK = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
4
5
 
5
6
  class Calendar
6
- WEEKS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
7
+ attr_reader :pdf_name, :month_title, :days
7
8
 
8
9
  def initialize(year, month, pdf_name)
9
- @first_of_month = Date.new(year, month, 1)
10
- @end_of_month = Date.new(year, month, -1)
11
- @days = (1..@end_of_month.day).map {|m| "%2d" % m}
12
- @first_of_month.wday.times {@days.unshift(" ")}
13
- set_pdf_name(pdf_name)
10
+ first_of_month = Date.new(year, month, 1)
11
+ end_of_month = Date.new(year, month, -1)
12
+ @days = (1..end_of_month.day).map {|m| "%2d" % m}
13
+ first_of_month.wday.times {@days.unshift(" ")}
14
+ @month_title = first_of_month.strftime("%B %Y")
15
+ set_pdf_name(pdf_name)
14
16
  end
15
17
 
16
18
  def set_pdf_name(name)
@@ -21,13 +23,9 @@ module Mcalendar
21
23
  end
22
24
  end
23
25
 
24
- def month_title
25
- @first_of_month.strftime("%B %Y")
26
- end
27
-
28
26
  def to_s
29
- week_header = WEEKS.join(" ")
30
- month_header = month_title.center(week_header.size).rstrip
27
+ week_header = Mcalendar::DAY_OF_WEEK.join(" ")
28
+ month_header = @month_title.center(week_header.size).rstrip
31
29
  calendar = [[week_header]]
32
30
  @days.each_slice(7) {|x| calendar << [x.join(" ")]}
33
31
  [month_header, calendar]
@@ -38,30 +36,7 @@ module Mcalendar
38
36
  end
39
37
 
40
38
  def pdf
41
- month_header = [[month_title]]
42
- calendar = [WEEKS]
43
- @days.each_slice(7) {|x| calendar << x}
44
-
45
- pdf = Prawn::Document.new(page_size: 'A4', margin: 20)
46
- # stroke_axis
47
- cell_height = calendar.size > 6 ? 50 : 60
48
-
49
- pdf.bounding_box([0, 400], width: 553, height: 400) do
50
- pdf.stroke_bounds
51
-
52
- pdf.table(month_header) do
53
- cells.style(width: 553, height: 59, align: :center, size: 26)
54
- row(0).padding_top = 15
55
- row(0).padding_bottom = 0
56
- end
57
-
58
- pdf.table(calendar) do
59
- cells.style(width: 79, height: cell_height, align: :center, size: 19, padding: 15)
60
- row(0).height = 40
61
- row(0).padding_top = 10
62
- row(0).padding_bottom = 0
63
- end
64
- end
39
+ pdf = Mcalendar::OutputPdf.new(self)
65
40
  pdf.render_file @pdf_name
66
41
  end
67
42
 
@@ -0,0 +1,49 @@
1
+ module Mcalendar
2
+ class OutputPdf < Prawn::Document
3
+
4
+ def initialize(obj_calendar)
5
+ @month_header = [[obj_calendar.month_title]]
6
+ @day_of_week = [Mcalendar::DAY_OF_WEEK]
7
+ @calendar = obj_calendar.days.each_slice(7).to_a
8
+ @cell_height = @calendar.size > 5 ? 50 : 60
9
+
10
+ super(page_size: 'A4', margin: 20)
11
+ calendar_render
12
+ end
13
+
14
+ def month_header
15
+ table(@month_header) do
16
+ cells.style(width: 553, height: 59, align: :center, size: 26)
17
+ row(0).padding_top = 15
18
+ row(0).padding_bottom = 0
19
+ end
20
+ end
21
+
22
+ def week_header
23
+ table(@day_of_week) do
24
+ cells.style(width: 79, height: 40, align: :center, size: 19)
25
+ row(0).padding_top = 10
26
+ row(0).padding_bottom = 0
27
+ end
28
+ end
29
+
30
+ def day_content
31
+ table(@calendar, cell_style: {height: @cell_height}) do
32
+ cells.style(width: 79, align: :center, size: 19)
33
+ row(0).padding = 15
34
+ end
35
+ end
36
+
37
+ def calendar_render
38
+ # stroke_axis
39
+
40
+ bounding_box([0, 400], width: 553, height: 400) do
41
+ stroke_bounds
42
+ month_header
43
+ week_header
44
+ day_content
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module Mcalendar
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/mcalendar.rb CHANGED
@@ -6,4 +6,5 @@ require "optparse"
6
6
  require_relative 'mcalendar/calendar'
7
7
  require_relative 'mcalendar/command'
8
8
  require_relative 'mcalendar/options'
9
+ require_relative 'mcalendar/output_pdf'
9
10
  require_relative 'mcalendar/version'
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.2.0
4
+ version: 0.2.1
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-08 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -87,6 +87,7 @@ files:
87
87
  - lib/mcalendar/calendar.rb
88
88
  - lib/mcalendar/command.rb
89
89
  - lib/mcalendar/options.rb
90
+ - lib/mcalendar/output_pdf.rb
90
91
  - lib/mcalendar/version.rb
91
92
  - mcalendar.gemspec
92
93
  homepage: https://github.com/icm7216/mcalendar