mcalendar 0.1.2 → 0.2.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: 0b53e3a3204aeaf586f32fd3a8765e5a23bf82815ba9c0288bb4e1fe86507ab6
4
- data.tar.gz: 4ee2fdd8a52460874411b9271937428fb21e63f037e1e0dffcf1247288cb3a40
3
+ metadata.gz: b957b8968e85884abff40ef75462a3061a99fe97d057f8a80c5360a8f1ba11a4
4
+ data.tar.gz: 508e4d57573f0bc0f0d44634553fe465cdab91efe94138c8385398d39fbf1e68
5
5
  SHA512:
6
- metadata.gz: 5d9f099a44377cdbb6a366ad04bf1c70e6b5d920ab40c975b72a08d28f02d4e8e48c2dcf306e8d15330a243a6b36ed98a4fdc47d3e2b2d12a72746b14bb2e536
7
- data.tar.gz: 35a5ba1a1a7d2de7be98ddacb66bf1c9a60212a2058438d83a592048031e62f01791d4ebd88fa430d2189b6dbb799e499be7652c38927f9408762713f6b0bc1a
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
@@ -5,6 +5,7 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  t.libs << "lib"
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
+ t.options = "-v"
8
9
  end
9
10
 
10
11
  task :default => :test
data/exe/mcalendar CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "mcalendar"
4
+
5
+ Mcalendar::Command.run(ARGV)
@@ -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 "calendar.pdf"
65
+ pdf.render_file @pdf_name
55
66
  end
56
67
 
57
68
  end
@@ -1,11 +1,35 @@
1
1
  # Ruby Monthly calendar
2
2
 
3
- begin
4
- d = Date.parse(ARGV.first)
5
- rescue
6
- d = Date.today
7
- end
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
- calendar = Mcalendar::Calendar.new(d.year, d.month)
10
- calendar.display
11
- calendar.pdf
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
@@ -1,3 +1,3 @@
1
1
  module Mcalendar
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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/version'
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.1.2
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-07 00:00:00.000000000 Z
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