mcalendar 0.1.2 → 0.2.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 +4 -4
- data/README.md +24 -1
- data/Rakefile +1 -0
- data/exe/mcalendar +2 -0
- data/lib/mcalendar/calendar.rb +13 -2
- data/lib/mcalendar/command.rb +32 -8
- data/lib/mcalendar/options.rb +37 -0
- data/lib/mcalendar/version.rb +1 -1
- data/lib/mcalendar.rb +3 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b957b8968e85884abff40ef75462a3061a99fe97d057f8a80c5360a8f1ba11a4
|
4
|
+
data.tar.gz: 508e4d57573f0bc0f0d44634553fe465cdab91efe94138c8385398d39fbf1e68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ec173986099a1c9d4070ccdb424b05093e5b2d70d54831595a6968d6ab7a08c7fa43b684d42986b00135c2455e7ad38d83f9b71ca36efca409f2a7a69e33aef
|
7
|
+
data.tar.gz: 5903ccb62a28c78ff60deb53635d28e8b2c6e401ca8a0f5d471c02b54773da584b3c335679923e20816e14beb8e14630e99ef1e479e930832113316363588770
|
data/README.md
CHANGED
@@ -30,12 +30,35 @@ When you run the command, the calendar appears on the console. The pdf file is c
|
|
30
30
|
mcalendar
|
31
31
|
```
|
32
32
|
|
33
|
-
|
34
33
|
If you want to create a calendar for any month.
|
35
34
|
```
|
36
35
|
mcalendar 2020/02
|
37
36
|
```
|
38
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
|
+
```
|
39
62
|
|
40
63
|
## License
|
41
64
|
|
data/Rakefile
CHANGED
data/exe/mcalendar
CHANGED
data/lib/mcalendar/calendar.rb
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
|
2
2
|
module Mcalendar
|
3
|
+
DEFAULT_PDF_NAME = "calendar.pdf"
|
4
|
+
|
3
5
|
class Calendar
|
4
6
|
WEEKS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
|
5
7
|
|
6
|
-
def initialize(year, month)
|
8
|
+
def initialize(year, month, pdf_name)
|
7
9
|
@first_of_month = Date.new(year, month, 1)
|
8
10
|
@end_of_month = Date.new(year, month, -1)
|
9
11
|
@days = (1..@end_of_month.day).map {|m| "%2d" % m}
|
10
12
|
@first_of_month.wday.times {@days.unshift(" ")}
|
13
|
+
set_pdf_name(pdf_name)
|
14
|
+
end
|
15
|
+
|
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
22
|
end
|
12
23
|
|
13
24
|
def month_title
|
@@ -51,7 +62,7 @@ module Mcalendar
|
|
51
62
|
row(0).padding_bottom = 0
|
52
63
|
end
|
53
64
|
end
|
54
|
-
pdf.render_file
|
65
|
+
pdf.render_file @pdf_name
|
55
66
|
end
|
56
67
|
|
57
68
|
end
|
data/lib/mcalendar/command.rb
CHANGED
@@ -1,11 +1,35 @@
|
|
1
1
|
# Ruby Monthly calendar
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Mcalendar
|
4
|
+
class Command
|
5
|
+
|
6
|
+
def self.run(argv)
|
7
|
+
new(argv).execute
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(argv)
|
11
|
+
@argv = argv
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
options = Mcalendar::Options.parse(@argv)
|
17
|
+
date = options[:date]
|
18
|
+
console = options[:opt][:console]
|
19
|
+
pdf = options[:opt][:pdf]
|
20
|
+
pdf_name = options[:opt][:name]
|
21
|
+
calendar = Mcalendar::Calendar.new(date.year, date.month, pdf_name)
|
22
|
+
|
23
|
+
# output calendar
|
24
|
+
calendar.display if console
|
25
|
+
calendar.pdf if pdf
|
26
|
+
|
27
|
+
# both outputs if no options
|
28
|
+
if console.nil? && pdf.nil?
|
29
|
+
calendar.display
|
30
|
+
calendar.pdf
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Mcalendar
|
2
|
+
module Options
|
3
|
+
|
4
|
+
def self.parse(argv)
|
5
|
+
options = {}
|
6
|
+
|
7
|
+
parser = OptionParser.new do |o|
|
8
|
+
o.on_head('-v', '--version', 'Show version') do
|
9
|
+
o.version = Mcalendar::VERSION
|
10
|
+
puts o.version
|
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}
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
remained = parser.parse!(argv)
|
19
|
+
rescue OptionParser::InvalidArgument => e
|
20
|
+
abort e.message
|
21
|
+
rescue OptionParser::MissingArgument => e
|
22
|
+
case e.args
|
23
|
+
when ["-n"], ["--name"]
|
24
|
+
options[:name] = Mcalendar::DEFAULT_PDF_NAME
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
d = Date.parse(remained.first)
|
30
|
+
rescue
|
31
|
+
d = Date.today
|
32
|
+
end
|
33
|
+
|
34
|
+
{date: d, opt: options}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/mcalendar/version.rb
CHANGED
data/lib/mcalendar.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'date'
|
2
2
|
require "prawn"
|
3
3
|
require "prawn/table"
|
4
|
+
require "optparse"
|
4
5
|
|
5
6
|
require_relative 'mcalendar/calendar'
|
6
7
|
require_relative 'mcalendar/command'
|
7
|
-
require_relative 'mcalendar/
|
8
|
+
require_relative 'mcalendar/options'
|
9
|
+
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2020-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/mcalendar.rb
|
87
87
|
- lib/mcalendar/calendar.rb
|
88
88
|
- lib/mcalendar/command.rb
|
89
|
+
- lib/mcalendar/options.rb
|
89
90
|
- lib/mcalendar/version.rb
|
90
91
|
- mcalendar.gemspec
|
91
92
|
homepage: https://github.com/icm7216/mcalendar
|