mcalendar 0.3.7 → 0.4.0

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: 1c37d4882b2dcea8a3df4b7e8802b319ccbfd1f650fe2fc90e6fb6fafa9919d3
4
- data.tar.gz: f6005e4ea03becf4302e45490dcd4a0f00230d6db48d1bec4d6411f7d45c9560
3
+ metadata.gz: 7a634777135f135d9aeae14ea0bc037a3974ebe8f1574d6d021a11f959d01cc7
4
+ data.tar.gz: 3afd599f14c4689099906def2f233f489ba990b09b4424422dad20dfd2b4e054
5
5
  SHA512:
6
- metadata.gz: '093c36d9b6ccfc75fe69e9c7fe4a406202e24c8592738f0b572f26dfe51802beadee078cfd84e32d4a2ee197406d1b2a97acb9b08e47de98efd1a3efd1f1ccb7'
7
- data.tar.gz: ca679323931aaa7cdf0803c2a386b15c23f20d2ecf0902769f4e7e2a770ea5fb8124c1eada288e0847e4dbaaf92045b3a248060cef24ed37828a9cdd7f188690
6
+ metadata.gz: 3f54acf7a0748733220713a0fb2395e881c2364e2ee76d95c4ce6f7840bcc5202a8f7f7b1c85eaf0aaa48782af05f063f29761a47cb4313101ca74e0ce0f18ec
7
+ data.tar.gz: d9f6e5f64f7668e771e7bb183f940f0c5d465e9544819abef54d773d8b3071ffe8f40e4e736cda4b373b26622b5967c32fd06bb4c2d63a1309df2a1339df352b
data/.gitignore CHANGED
@@ -1,12 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /Gemfile.lock
10
- pdf/*.pdf
11
- *.pdf
12
- /.vscode/
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
10
+ pdf/*.pdf
11
+ *.pdf
12
+ /.vscode/
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in mcalendar.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 12.0"
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mcalendar.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,65 +1,65 @@
1
-
2
- # Mcalendar [![Gem Version](https://badge.fury.io/rb/mcalendar.svg)](https://badge.fury.io/rb/mcalendar)
3
-
4
- Ruby monthly calendar, console and pdf.
5
- This calendar includes Japanese holidays.
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'mcalendar'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install mcalendar
22
-
23
-
24
- ## Usage
25
-
26
- If you want to create a calendar for this month.
27
-
28
- When you run the command, the calendar appears on the console. The pdf file is created in the current directory.
29
- ```
30
- mcalendar
31
- ```
32
-
33
- If you want to create a calendar for any month.
34
- ```
35
- mcalendar 2020/02
36
- ```
37
-
38
- If you want to output only PDF, use the `-p` option.
39
- ```
40
- mcalendar 2020/02 -p
41
- ```
42
-
43
- Also, If you want to output only console, use the `-c` option.
44
- ```
45
- mcalendar 2020/02 -c
46
- ```
47
-
48
- The default PDF file name is `calendar.pdf`. You can specify any name using the `-n` option.
49
- ```
50
- mcalendar 2020/02 -n my_calendar.pdf
51
- ```
52
-
53
- show help
54
- ```
55
- >mcalendar -h
56
- Usage: mcalendar [options]
57
- -v, --version Show version
58
- -p, --pdf output pdf
59
- -n, --name=NAME output pdf name
60
- -c, --console output console
61
- ```
62
-
63
- ## License
64
-
65
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1
+
2
+ # Mcalendar [![Gem Version](https://badge.fury.io/rb/mcalendar.svg)](https://badge.fury.io/rb/mcalendar)
3
+
4
+ Ruby monthly calendar, console and pdf.
5
+ This calendar includes Japanese holidays.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'mcalendar'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install mcalendar
22
+
23
+
24
+ ## Usage
25
+
26
+ If you want to create a calendar for this month.
27
+
28
+ When you run the command, the calendar appears on the console. The pdf file is created in the current directory.
29
+ ```
30
+ mcalendar
31
+ ```
32
+
33
+ If you want to create a calendar for any month.
34
+ ```
35
+ mcalendar 2020/02
36
+ ```
37
+
38
+ If you want to output only PDF, use the `-p` option.
39
+ ```
40
+ mcalendar 2020/02 -p
41
+ ```
42
+
43
+ Also, If you want to output only console, use the `-c` option.
44
+ ```
45
+ mcalendar 2020/02 -c
46
+ ```
47
+
48
+ The default PDF file name is `calendar.pdf`. You can specify any name using the `-n` option.
49
+ ```
50
+ mcalendar 2020/02 -n my_calendar.pdf
51
+ ```
52
+
53
+ show help
54
+ ```
55
+ >mcalendar -h
56
+ Usage: mcalendar [options]
57
+ -v, --version Show version
58
+ -p, --pdf output pdf
59
+ -n, --name=NAME output pdf name
60
+ -c, --console output console
61
+ ```
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -2,41 +2,37 @@
2
2
  module Mcalendar
3
3
 
4
4
  class Calendar
5
- attr_reader :pdf_name, :month_title, :days, :first_of_month, :end_of_month
6
5
 
7
- def initialize(year, month, pdf_name)
8
- @first_of_month = Date.new(year, month, 1)
9
- @end_of_month = Date.new(year, month, -1)
10
- @days = (1..end_of_month.day).map {|m| "%2d" % m}
11
- first_of_month.wday.times {@days.unshift(" ")}
12
- @month_title = first_of_month.strftime("%B %Y")
13
- set_pdf_name(pdf_name)
6
+ def initialize(year, month)
7
+ @year = year
8
+ @month = month
14
9
  end
15
10
 
16
- def set_pdf_name(name)
17
- if name.nil? || name.empty?
18
- @pdf_name = Mcalendar::DEFAULT_PDF_NAME
19
- else
20
- @pdf_name = name
21
- end
11
+ def first_of_month
12
+ Date.new(@year, @month, 1)
13
+ end
14
+
15
+ def end_of_month
16
+ Date.new(@year, @month, -1)
17
+ end
18
+
19
+ def days
20
+ days = (1..end_of_month.day).map {|m| "%2d" % m}
21
+ first_of_month.wday.times {days.unshift(" ")}
22
+ days
23
+ end
24
+
25
+ def month_title
26
+ first_of_month.strftime("%B %Y")
22
27
  end
23
28
 
24
29
  def to_s
25
30
  week_header = Mcalendar::DAY_OF_WEEK.join(" ")
26
- month_header = @month_title.center(week_header.size).rstrip
31
+ month_header = month_title.center(week_header.size).rstrip
27
32
  calendar = [[week_header]]
28
- @days.each_slice(7) {|x| calendar << [x.join(" ")]}
33
+ days.each_slice(7) {|x| calendar << [x.join(" ")]}
29
34
  [month_header, calendar]
30
35
  end
31
-
32
- def display
33
- puts to_s
34
- end
35
-
36
- def pdf
37
- pdf = Mcalendar::OutputPdf.new(self)
38
- pdf.render_file @pdf_name
39
- end
40
36
 
41
37
  end
42
38
  end
@@ -9,24 +9,42 @@ module Mcalendar
9
9
  def initialize(argv)
10
10
  @argv = argv
11
11
  end
12
+
13
+ def output_console
14
+ puts @calendar.to_s
15
+ end
16
+
17
+ def output_pdf
18
+ @outputpdf.render_file(pdf_filename)
19
+ end
20
+
21
+ def pdf_filename
22
+ if @pdf_name.nil? || @pdf_name.empty?
23
+ Mcalendar::DEFAULT_PDF_NAME
24
+ else
25
+ @pdf_name = @pdf_name.downcase.end_with?(".pdf")? @pdf_name : @pdf_name + ".pdf"
26
+ end
27
+ end
12
28
 
13
29
  def execute
14
30
  options = Mcalendar::Options.parse(@argv)
15
31
  date = options[:date]
16
32
  console = options[:opt][:console]
17
33
  pdf = options[:opt][:pdf]
18
- pdf_name = options[:opt][:name]
34
+ @pdf_name = options[:opt][:name]
19
35
  version = options[:opt][:version]
20
- calendar = Mcalendar::Calendar.new(date.year, date.month, pdf_name)
36
+ @calendar = Mcalendar::Calendar.new(date.year, date.month)
37
+ @outputpdf = Mcalendar::OutputPdf.new(@calendar)
21
38
 
22
39
  # output calendar
23
- calendar.display if console
24
- calendar.pdf if pdf
40
+ output_console if console
41
+ output_pdf if pdf
42
+
25
43
 
26
44
  # both outputs if no options
27
45
  if console.nil? && pdf.nil? && version.nil?
28
- calendar.display
29
- calendar.pdf
46
+ output_console
47
+ output_pdf
30
48
  end
31
49
  end
32
50
  end
@@ -30,33 +30,41 @@ module Mcalendar
30
30
  :anniversary_text
31
31
  )
32
32
 
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
33
+ class Schedule
34
+ extend Forwardable
35
+ def_delegators :@calendar, :first_of_month, :end_of_month
37
36
 
37
+ def initialize(calendar)
38
+ @calendar = calendar
38
39
  @days_config = Hash.new(nil)
40
+
41
+ setup_schedule
42
+ end
43
+
44
+
45
+ def setup_schedule
39
46
  holiday_description_language
40
47
  days_basic
41
- holiday
42
- anniversary
48
+ holidays_in_the_month
49
+ anniversaries_in_the_month
50
+ end
51
+
52
+ def holiday_description_language
53
+ Mcalendar.const_set(:HOLIDAY, Mcalendar::EN::HOLIDAY)
54
+ Mcalendar.const_set(:ANNIVERSARY, Mcalendar::EN::ANNIVERSARY)
43
55
  end
44
56
 
45
57
  def days_basic
46
- (@first_of_month..@end_of_month).each do |date|
58
+ (first_of_month..end_of_month).each do |date|
47
59
  d_sym = date.strftime("%Y%m%d").to_sym
48
60
  @days_config[d_sym] = Config_day.new(date.day, :black, nil, nil)
49
61
  end
62
+ @days_config
50
63
  end
51
64
 
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)
65
+ def holidays_in_the_month
66
+ y = format("%4d", first_of_month.year)
67
+ m = format("%02d", first_of_month.month)
60
68
  regex = /#{y}#{m}\d\d/
61
69
 
62
70
  Mcalendar::HOLIDAY.keys.grep(regex).each do |d|
@@ -64,23 +72,25 @@ module Mcalendar
64
72
  @days_config[d].day_color = :red
65
73
  @days_config[d].holiday_text = Mcalendar::HOLIDAY[d]
66
74
  end
75
+ @days_config
67
76
  end
68
77
 
69
- def anniversary
70
- y = format("%4d", @first_of_month.year)
71
- m = format("%02d", @first_of_month.month)
78
+ def anniversaries_in_the_month
79
+ y = format("%4d", first_of_month.year)
80
+ m = format("%02d", first_of_month.month)
72
81
  regex = /#{y}#{m}\d\d/
73
82
 
74
83
  Mcalendar::ANNIVERSARY.keys.grep(regex).each do |d|
75
84
  @days_config[d].day = Date.parse(d.to_s).day
76
85
  @days_config[d].anniversary_text = Mcalendar::ANNIVERSARY[d]
77
86
  end
87
+ @days_config
78
88
  end
79
89
 
80
- def days
81
- pdf_days = @days_config.each_value.map { |val| val }
82
- @first_of_month.wday.times { pdf_days.unshift(" ") }
83
- pdf_days
90
+ def daily_schedule
91
+ daily = @days_config.each_value.map { |val| val }
92
+ first_of_month.wday.times { daily.unshift(" ") }
93
+ daily
84
94
  end
85
95
  end
86
96
  end
@@ -1,19 +1,17 @@
1
1
  module Mcalendar
2
2
  class OutputPdf < Prawn::Document
3
- include Mcalendar::Config
3
+ extend Forwardable
4
+ def_delegator :@calendar, :month_title
4
5
 
5
- def initialize(obj_calendar)
6
- @first_of_month = obj_calendar.first_of_month
7
- @end_of_month = obj_calendar.end_of_month
8
- @month_header = [[obj_calendar.month_title]]
6
+ def initialize(calendar)
7
+ @calendar = calendar
8
+ @month_header = [[month_title]]
9
9
  @day_of_week = [Mcalendar::DAY_OF_WEEK]
10
-
11
- @pdf_days = []
12
- days_information
13
- @pdf_days = days
14
- @calendar = @pdf_days.each_slice(7).map
15
- @day_height = @calendar.size > 5 ? 20 : 20
16
- @text_height = @calendar.size > 5 ? 30 : 40
10
+
11
+ schedule = Mcalendar::Schedule.new(calendar)
12
+ @weekly_schedule = schedule.daily_schedule.each_slice(7).map
13
+ @day_height = @weekly_schedule.size > 5 ? 20 : 20
14
+ @text_height = @weekly_schedule.size > 5 ? 30 : 40
17
15
 
18
16
  super(page_size: 'A4', margin: 20)
19
17
  calendar_render
@@ -36,8 +34,8 @@ module Mcalendar
36
34
  end
37
35
  end
38
36
 
39
- def day_content
40
- @calendar.each do |c|
37
+ def days_schedule
38
+ @weekly_schedule.each do |c|
41
39
  row_day = c.map {|x| (x.class == Struct::ConfigDay) ? x.day : x}
42
40
  row_color = c.map {|x| (x.class == Struct::ConfigDay) ? x.day_color : :black}
43
41
  row_text = c.map do |x|
@@ -80,7 +78,7 @@ module Mcalendar
80
78
  stroke_bounds
81
79
  month_header
82
80
  week_header
83
- day_content
81
+ days_schedule
84
82
  end
85
83
  end
86
84
 
@@ -1,3 +1,3 @@
1
- module Mcalendar
2
- VERSION = "0.3.7"
3
- end
1
+ module Mcalendar
2
+ VERSION = "0.4.0"
3
+ end
data/lib/mcalendar.rb CHANGED
@@ -1,12 +1,13 @@
1
- require 'date'
2
- require "prawn"
3
- require "prawn/table"
4
- require "optparse"
5
-
6
- require_relative 'mcalendar/calendar'
7
- require_relative 'mcalendar/command'
8
- require_relative 'mcalendar/config'
9
- require_relative 'mcalendar/holiday'
10
- require_relative 'mcalendar/options'
11
- require_relative 'mcalendar/output_pdf'
12
- require_relative 'mcalendar/version'
1
+ require 'date'
2
+ require "prawn"
3
+ require "prawn/table"
4
+ require "optparse"
5
+ require 'forwardable'
6
+
7
+ require_relative 'mcalendar/calendar'
8
+ require_relative 'mcalendar/command'
9
+ require_relative 'mcalendar/config'
10
+ require_relative 'mcalendar/holiday'
11
+ require_relative 'mcalendar/options'
12
+ require_relative 'mcalendar/output_pdf'
13
+ require_relative 'mcalendar/version'
data/mcalendar.gemspec CHANGED
@@ -1,31 +1,32 @@
1
- require_relative 'lib/mcalendar/version'
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "mcalendar"
5
- spec.version = Mcalendar::VERSION
6
- spec.authors = ["icm7216"]
7
- spec.email = ["icm7216d@gmail.com"]
8
-
9
- spec.summary = %q{Ruby Monthly calendar}
10
- spec.description = %q{Ruby Monthly Calendar, Console and pdf}
11
- spec.homepage = "https://github.com/icm7216/mcalendar"
12
- spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
-
15
- # Specify which files should be added to the gem when it is released.
16
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_runtime_dependency "prawn"
25
- spec.add_runtime_dependency "prawn-table"
26
-
27
- spec.add_development_dependency "test-unit"
28
- spec.add_development_dependency "test-unit-rr"
29
- spec.add_development_dependency "prawn"
30
- spec.add_development_dependency "prawn-table"
31
- end
1
+ require_relative 'lib/mcalendar/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "mcalendar"
5
+ spec.version = Mcalendar::VERSION
6
+ spec.authors = ["icm7216"]
7
+ spec.email = ["icm7216d@gmail.com"]
8
+
9
+ spec.summary = %q{Ruby Monthly calendar}
10
+ spec.description = %q{Ruby Monthly Calendar, Console and pdf}
11
+ spec.homepage = "https://github.com/icm7216/mcalendar"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "prawn"
25
+ spec.add_runtime_dependency "prawn-table"
26
+
27
+ spec.add_development_dependency "test-unit"
28
+ spec.add_development_dependency "test-unit-rr"
29
+ spec.add_development_dependency "prawn"
30
+ spec.add_development_dependency "prawn-table"
31
+ spec.add_development_dependency "rake"
32
+ 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.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - icm7216
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-04 00:00:00.000000000 Z
11
+ date: 2021-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Ruby Monthly Calendar, Console and pdf
98
112
  email:
99
113
  - icm7216d@gmail.com