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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c413c998aafb8d17962a9610bad85958075a2779d7fc1cbf0859037ffe5c8e95
4
- data.tar.gz: 931462951e2ee6ae342405aad95e7a09d93d6e1a315d4c593b9f2e2c368894cf
3
+ metadata.gz: c9557f17e35790f52927ea11905d943692e0a5973a68373204705e2991e380c6
4
+ data.tar.gz: b42a73edc44c7dc061e59d4e85cc38b34b67981bd7ac81e1f979cd8501f43eba
5
5
  SHA512:
6
- metadata.gz: 833c63b6fa24b4f5b18b505ede13cd069b9fccff1cdbf83ba2c1b1bd482c8b23a8c6eb1967090d5b68af0e288ecc3330b1f4225c19b272512b2c5e1d4c57da64
7
- data.tar.gz: 0d83b7e80cd2b54a005919a95da5e5f34cda5604a1512f6f53e3c283b147843195edbc920c7fe86d80a8720dbd2b6d427b5fda6a2d0224098d7d7734d4b0441a
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
- show help
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
@@ -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
- days.each_slice(7) {|x| calendar << [x.join(" ")]}
53
+ reverse_todays_date.each_slice(7) {|x| calendar << [x.join(" ")]}
34
54
  [month_header, calendar]
35
55
  end
36
56
 
@@ -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
- @outputpdf.render_file(pdf_filename)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Mcalendar
2
- VERSION = "0.5.4"
2
+ VERSION = "0.6.1"
3
3
  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.5.4
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-04-24 00:00:00.000000000 Z
11
+ date: 2022-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn