mcalendar 0.5.4 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -1
- data/lib/mcalendar/calendar.rb +21 -1
- data/lib/mcalendar/command.rb +47 -18
- data/lib/mcalendar/options.rb +2 -0
- data/lib/mcalendar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9557f17e35790f52927ea11905d943692e0a5973a68373204705e2991e380c6
|
4
|
+
data.tar.gz: b42a73edc44c7dc061e59d4e85cc38b34b67981bd7ac81e1f979cd8501f43eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2385cb49e422f191b2391ee78754370362a4090afaaa9c924f36b902f2ba69394e31d46cbf524d7aee286b25ffbed4af5d20b01841c9e83fc0bfb3350942f9ef
|
7
|
+
data.tar.gz: 36a5585b38178fec46f7face229ac766a666f3962b4ef6e4dcadb6be96a014906860ae24fcc71dde065b374513033ebe0ed835eb8dd0809a2d96560200128890
|
data/README.md
CHANGED
@@ -142,8 +142,24 @@ You can also use the command option `-f` or `--config=` to load your own `your_s
|
|
142
142
|
>mcalendar -f your_schedule.yml
|
143
143
|
```
|
144
144
|
|
145
|
+
How many Sundays are there this month?
|
146
|
+
Use the command option `-w`, You can easily know this answer.
|
147
|
+
```
|
148
|
+
>mcalendar -w
|
149
|
+
|
150
|
+
Number of days for each day of the week in August 2022
|
151
|
+
-----------------------------------------------------------------------
|
152
|
+
Sun. 4 days. => 7,14,21,28
|
153
|
+
Mon. 5 days. => 1, 8,15,22,29
|
154
|
+
Tue. 5 days. => 2, 9,16,23,30
|
155
|
+
Wed. 5 days. => 3,10,17,24,31
|
156
|
+
Thu. 4 days. => 4,11,18,25
|
157
|
+
Fri. 4 days. => 5,12,19,26
|
158
|
+
Sat. 4 days. => 6,13,20,27
|
159
|
+
```
|
160
|
+
|
145
161
|
|
146
|
-
|
162
|
+
Show help
|
147
163
|
```
|
148
164
|
>mcalendar --help
|
149
165
|
Usage: mcalendar [options]
|
@@ -153,6 +169,7 @@ Usage: mcalendar [options]
|
|
153
169
|
-c, --console output console
|
154
170
|
-f, --config=FILE Use YAML format file.
|
155
171
|
-y, --holidays Display holidays and anniversaries in YAML file
|
172
|
+
-w, --wday Number of days for each day of the week in this month
|
156
173
|
```
|
157
174
|
|
158
175
|
## License
|
data/lib/mcalendar/calendar.rb
CHANGED
@@ -26,11 +26,31 @@ module Mcalendar
|
|
26
26
|
first_of_month.strftime("%B %Y")
|
27
27
|
end
|
28
28
|
|
29
|
+
def this_month_calendar?
|
30
|
+
(Date.today.year == @year) && (Date.today.month == @month)
|
31
|
+
end
|
32
|
+
|
33
|
+
def reverse_color(day_str)
|
34
|
+
"\e[7m" + day_str.to_s + "\e[0m"
|
35
|
+
end
|
36
|
+
|
37
|
+
def reverse_todays_date
|
38
|
+
today_str = format("%2s", Date.today.day.to_s)
|
39
|
+
|
40
|
+
if this_month_calendar?
|
41
|
+
month_days = days.map {|x| x.sub(today_str, reverse_color(today_str))}
|
42
|
+
else
|
43
|
+
month_days = days
|
44
|
+
end
|
45
|
+
|
46
|
+
month_days
|
47
|
+
end
|
48
|
+
|
29
49
|
def to_s
|
30
50
|
week_header = Mcalendar::DAY_OF_WEEK.join(" ")
|
31
51
|
month_header = month_title.center(week_header.size).rstrip
|
32
52
|
calendar = [[week_header]]
|
33
|
-
|
53
|
+
reverse_todays_date.each_slice(7) {|x| calendar << [x.join(" ")]}
|
34
54
|
[month_header, calendar]
|
35
55
|
end
|
36
56
|
|
data/lib/mcalendar/command.rb
CHANGED
@@ -7,15 +7,53 @@ module Mcalendar
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize(argv)
|
10
|
-
@argv = argv
|
10
|
+
# @argv = argv
|
11
|
+
options = Mcalendar::Options.new.parse(argv)
|
12
|
+
@date = options[:date]
|
13
|
+
|
14
|
+
@console = options[:console]
|
15
|
+
@pdf = options[:pdf]
|
16
|
+
@pdf_name = options[:name]
|
17
|
+
@version = options[:version]
|
18
|
+
@holidays = options[:holidays]
|
19
|
+
@calendar = Mcalendar::Calendar.new(@date.year, @date.month)
|
20
|
+
@schedule = Mcalendar::Schedule.new(@calendar, options)
|
21
|
+
@wday = options[:wday]
|
11
22
|
end
|
12
23
|
|
13
24
|
def output_console
|
14
25
|
puts @calendar.to_s
|
15
26
|
end
|
16
27
|
|
28
|
+
# Number of days for each day of the week in this month.
|
29
|
+
def how_many_days
|
30
|
+
wdays = Mcalendar::DAY_OF_WEEK.map {|w| w.capitalize + "."}
|
31
|
+
wvalues = day_of_weeks.values
|
32
|
+
|
33
|
+
puts "\nNumber of days for each day of the week in #{@date.strftime("%B %Y")}"
|
34
|
+
puts "------------------------------------------------------------"
|
35
|
+
wdays.each_with_index do |wday, idx|
|
36
|
+
puts "#{wday} #{wvalues[idx].size} days. => #{wvalues[idx].join(",")}"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def day_of_weeks
|
42
|
+
wks = @calendar.days.each_slice(7).map(&:to_a)
|
43
|
+
keys = Mcalendar::DAY_OF_WEEK.map(&:downcase).map(&:to_sym)
|
44
|
+
|
45
|
+
vals = (0..6).map do |wd|
|
46
|
+
w = wks.map {|wk| wk[wd]}
|
47
|
+
w.delete(" ")
|
48
|
+
w.compact
|
49
|
+
end
|
50
|
+
|
51
|
+
Hash[keys.zip(vals)]
|
52
|
+
end
|
53
|
+
|
17
54
|
def output_pdf
|
18
|
-
|
55
|
+
outputpdf = Mcalendar::OutputPdf.new(@calendar, @schedule)
|
56
|
+
outputpdf.render_file(pdf_filename)
|
19
57
|
end
|
20
58
|
|
21
59
|
def output_holidays
|
@@ -34,28 +72,19 @@ module Mcalendar
|
|
34
72
|
end
|
35
73
|
|
36
74
|
def execute
|
37
|
-
options = Mcalendar::Options.new.parse(@argv)
|
38
|
-
date = options[:date]
|
39
|
-
console = options[:console]
|
40
|
-
pdf = options[:pdf]
|
41
|
-
@pdf_name = options[:name]
|
42
|
-
version = options[:version]
|
43
|
-
holidays = options[:holidays]
|
44
|
-
|
45
|
-
@calendar = Mcalendar::Calendar.new(date.year, date.month)
|
46
|
-
@schedule = Mcalendar::Schedule.new(@calendar, options)
|
47
|
-
@outputpdf = Mcalendar::OutputPdf.new(@calendar, @schedule)
|
48
|
-
|
49
75
|
# output calendar
|
50
|
-
output_console if console
|
51
|
-
output_pdf if pdf
|
52
|
-
output_holidays if holidays
|
76
|
+
output_console if @console
|
77
|
+
output_pdf if @pdf
|
78
|
+
output_holidays if @holidays
|
53
79
|
|
54
80
|
# both outputs if no options
|
55
|
-
if console.nil? && pdf.nil? && version.nil? && holidays.nil?
|
81
|
+
if @console.nil? && @pdf.nil? && @version.nil? && @holidays.nil? && @wday.nil?
|
56
82
|
output_console
|
57
83
|
output_pdf
|
58
84
|
end
|
85
|
+
|
86
|
+
# Number of days for each day of the week in this month.
|
87
|
+
how_many_days if @wday
|
59
88
|
|
60
89
|
end
|
61
90
|
end
|
data/lib/mcalendar/options.rb
CHANGED
@@ -57,6 +57,8 @@ module Mcalendar
|
|
57
57
|
end
|
58
58
|
|
59
59
|
o.on("-y", "--holidays", "Display holidays and anniversaries in YAML file") { |v| @options[:holidays] = v }
|
60
|
+
|
61
|
+
o.on("-w", "--wday", "Number of days for each day of the week in this month") { |v| @options[:wday] = v }
|
60
62
|
end
|
61
63
|
|
62
64
|
begin
|
data/lib/mcalendar/version.rb
CHANGED
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.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- icm7216
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prawn
|