xcal 2.0.0 → 2.1.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
  SHA1:
3
- metadata.gz: 381a7242d8cc072c67ca700f455f96a7ce793d5e
4
- data.tar.gz: da3ccee9b1e44f40e3b56a54ca5cc313e7fcdf5b
3
+ metadata.gz: c428b7d20554555f682cdedb790233cbe56016d0
4
+ data.tar.gz: ac7fff1bd5b7fb5f3e49efb93e4fbbd78fb9817b
5
5
  SHA512:
6
- metadata.gz: 37fd55ddc8f6e0b79685bd2e0320bb025ce9f9bdfd2a008b5c39c573107eeea0e73e6d32e48b5071aa7565e864382de72038afa6e43a747557e61eaa38e3d96d
7
- data.tar.gz: 3544167b6037474f8e0da456e000775b76f195d439f67fec8e4cd34f2715ea0aeed4af7df36988e83cf6dd032860e98764727c4d141b7788a170f69ded909239
6
+ metadata.gz: 1718c31a659f8ab85df6c2e85716626ec42e44f1a32323446fdb330da8265bc893320a4aef5d38ad2b83a4a565727e24d0a06365b3f97320290e847e87e5f2ad
7
+ data.tar.gz: 0ad9116449e3bba907c2449921a4693380c3a9f09baa2e43d583d15534ba86c87f6cdb8fd7d1b5d4dd7180a65b4215ed0441b40f1530a4512edca1f270d12423
data/README.md CHANGED
@@ -1,6 +1,130 @@
1
- xcal
2
- ====
1
+ # xcal
3
2
 
4
- xcalは日本の祝日に対応したcal, ncalライクなカレンダーコマンドです。
5
- 祝日の情報はGoogleが提供するiCalを利用し、表示のたびにダウンロードします。
6
- カレンダーはカラフルに土曜日が青色、日曜日と祝日が赤色で表示されます。
3
+ xcalは休日の色付き表示に対応したcal, ncalライクなカレンダーコマンドです。
4
+ 休日の情報は表示のたびにiCal(icsファイル)をダウンロードして取得します。
5
+ デフォルトではGoogleが提供するiCalを利用し日本の休日を表示します。
6
+ また任意のicsファイルを指定して休日を表示することもできます。
7
+ カレンダーはカラフルに土曜日が青色、日曜日と休日が赤色で表示されます。
8
+
9
+ ## インストール
10
+
11
+ ```
12
+ # gem install xcal
13
+ ```
14
+
15
+ ## 使い方
16
+
17
+ デフォルトで前後1ヶ月の3ヶ月分のカレンダーを表示します。(実際は色付きです)
18
+
19
+ ```
20
+ $ xcal
21
+ November 2017 December 2017 January 2018
22
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
23
+ 1 2 3 4 1 2 1 2 3 4 5 6
24
+ 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
25
+ 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
26
+ 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
27
+ 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 31
28
+ 31
29
+ ```
30
+
31
+ `-l`オプションで休日の詳細を表示することができます。(iCalの`summary`を表示します)
32
+
33
+ ```
34
+ $ xcal -l
35
+ November 2017 December 2017 January 2018
36
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
37
+ 1 2 3 4 1 2 1 2 3 4 5 6
38
+ 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
39
+ 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
40
+ 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
41
+ 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 31
42
+ 31
43
+ 2017-11-03 (Fr) 文化の日
44
+ 2017-11-23 (Th) 勤労感謝の日
45
+ 2017-12-23 (Sa) 天皇誕生日
46
+ 2018-01-01 (Mo) 元日
47
+ 2018-01-08 (Mo) 成人の日
48
+ ```
49
+
50
+ `-9`オプションで前後4ヶ月の9ヶ月分のカレンダーを表示します。
51
+
52
+ ```
53
+ $ xcal -9
54
+ August 2017 September 2017 October 2017
55
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
56
+ 1 2 3 4 5 1 2 1 2 3 4 5 6 7
57
+ 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
58
+ 13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
59
+ 20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
60
+ 27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
61
+
62
+ November 2017 December 2017 January 2018
63
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
64
+ 1 2 3 4 1 2 1 2 3 4 5 6
65
+ 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
66
+ 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
67
+ 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
68
+ 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 31
69
+ 31
70
+ February 2018 March 2018 April 2018
71
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
72
+ 1 2 3 1 2 3 1 2 3 4 5 6 7
73
+ 4 5 6 7 8 9 10 4 5 6 7 8 9 10 8 9 10 11 12 13 14
74
+ 11 12 13 14 15 16 17 11 12 13 14 15 16 17 15 16 17 18 19 20 21
75
+ 18 19 20 21 22 23 24 18 19 20 21 22 23 24 22 23 24 25 26 27 28
76
+ 25 26 27 28 25 26 27 28 29 30 31 29 30
77
+ ```
78
+
79
+ 環境変数`XCAL_ICS_URL`にicsファイルのURLを指定すると日本以外の休日を表示することもできます。
80
+ 以下はアメリカ合衆国の休日のicsファイルを読み込ませてアメリカ合衆国のカレンダーを表示する例です。
81
+
82
+ ```
83
+ $ export XCAL_ICS_URL=https://calendar.google.com/calendar/ical/ja.usa%23holiday%40group.v.calendar.google.com/public/basic.ics
84
+ $ xcal -9 -l
85
+ August 2017 September 2017 October 2017
86
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
87
+ 1 2 3 4 5 1 2 1 2 3 4 5 6 7
88
+ 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
89
+ 13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
90
+ 20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
91
+ 27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
92
+
93
+ November 2017 December 2017 January 2018
94
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
95
+ 1 2 3 4 1 2 1 2 3 4 5 6
96
+ 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
97
+ 12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
98
+ 19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
99
+ 26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 31
100
+ 31
101
+ February 2018 March 2018 April 2018
102
+ Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
103
+ 1 2 3 1 2 3 1 2 3 4 5 6 7
104
+ 4 5 6 7 8 9 10 4 5 6 7 8 9 10 8 9 10 11 12 13 14
105
+ 11 12 13 14 15 16 17 11 12 13 14 15 16 17 15 16 17 18 19 20 21
106
+ 18 19 20 21 22 23 24 18 19 20 21 22 23 24 22 23 24 25 26 27 28
107
+ 25 26 27 28 25 26 27 28 29 30 31 29 30
108
+
109
+ 2017-09-04 (Mo) Labor Day
110
+ 2017-10-09 (Mo) Columbus Day (regional holiday)
111
+ 2017-10-31 (Tu) Halloween
112
+ 2017-11-05 (Su) Daylight Saving Time ends
113
+ 2017-11-10 (Fr) Veterans Day observed
114
+ 2017-11-11 (Sa) Veterans Day
115
+ 2017-11-23 (Th) Thanksgiving Day
116
+ 2017-12-24 (Su) Christmas Eve
117
+ 2017-12-25 (Mo) Christmas Day
118
+ 2017-12-31 (Su) New Year's Eve
119
+ 2018-01-01 (Mo) New Year's Day
120
+ 2018-01-15 (Mo) Martin Luther King Jr. Day
121
+ 2018-02-14 (We) Valentine's Day
122
+ 2018-02-19 (Mo) Presidents' Day
123
+ 2018-03-11 (Su) Daylight Saving Time starts
124
+ 2018-04-01 (Su) Easter Sunday
125
+ 2018-04-13 (Fr) Thomas Jefferson's Birthday
126
+ ```
127
+
128
+ ## License
129
+
130
+ This software is distributed under the MIT license.
data/exe/xcal CHANGED
@@ -2,6 +2,5 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'xcal'
5
- include Xcal
6
5
 
7
- main()
6
+ Xcal::Xcal.new.main(ARGV)
@@ -1,6 +1,9 @@
1
- require 'date'
2
- require 'open-uri'
3
- require 'icalendar'
1
+ module Xcal
2
+ require 'date'
3
+ require 'open-uri'
4
4
 
5
- require "xcal/version"
6
- require "xcal/xcal"
5
+ require 'icalendar'
6
+
7
+ require "xcal/version"
8
+ require "xcal/xcal"
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Xcal
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -1,4 +1,4 @@
1
- module Xcal
1
+ class Xcal::Xcal
2
2
  BLUE = "\e[34m"
3
3
  RED = "\e[31m"
4
4
  REVERSE = "\e[7m"
@@ -16,7 +16,7 @@ module Xcal
16
16
  REVERSE + str + CLEAR
17
17
  end
18
18
 
19
- URL = 'https://www.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics'
19
+ ICS_URL = ENV['XCAL_ICS_URL'] || 'https://www.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics'
20
20
 
21
21
  MONTH_TEMPLATE = [
22
22
  " January % ",
@@ -44,9 +44,9 @@ module Xcal
44
44
  [red('Su'), 'Mo', 'Tu', 'We', 'Th', 'Fr', blue('Sa')]
45
45
  end
46
46
 
47
- def get_japan_holidays()
47
+ def fetch_holidays_from_remote_ics(ics_url)
48
48
  holidays = {}
49
- ical = open(URL){|f| f.read}
49
+ ical = open(ics_url){|f| f.read}
50
50
  cals = Icalendar::Calendar.parse(ical)
51
51
  cals.each{|cal|
52
52
  cal.events.each{|event|
@@ -58,7 +58,7 @@ module Xcal
58
58
 
59
59
  holidays[y] = {} unless holidays[y]
60
60
  holidays[y][m] = {} unless holidays[y][m]
61
- holidays[y][m][d] = true
61
+ holidays[y][m][d] = {holiday: true, date: Date.new(y, m, d), summary: event.summary}
62
62
  }
63
63
  }
64
64
 
@@ -89,7 +89,7 @@ module Xcal
89
89
  end
90
90
 
91
91
  def is_holiday?(y, m, d, holidays)
92
- holidays[y] and holidays[y][m] and holidays[y][m][d]
92
+ holidays[y] and holidays[y][m] and holidays[y][m][d] and holidays[y][m][d][:holiday]
93
93
  end
94
94
 
95
95
  def month_header(y, m)
@@ -104,9 +104,43 @@ module Xcal
104
104
  day
105
105
  end
106
106
 
107
- def main()
108
- japan_holidays = get_japan_holidays()
107
+ def main(argv)
108
+ @holidays = fetch_holidays_from_remote_ics(ICS_URL)
109
109
 
110
+ if argv.include?('-9')
111
+ cal9
112
+ else
113
+ cal3
114
+ end
115
+
116
+ if argv.include?('-l')
117
+ if argv.include?('-9')
118
+ first = (Date.today << 4) - (Date.today.day - 1)
119
+ last = (Date.today >> 5) - Date.today.day
120
+ else
121
+ first = (Date.today << 1) - (Date.today.day - 1)
122
+ last = (Date.today >> 2) - Date.today.day
123
+ end
124
+
125
+ list_holidays(first, last)
126
+ end
127
+ end
128
+
129
+ def cal3
130
+ origin_date = Date.today
131
+
132
+ print_3month_calendar(origin_date)
133
+ end
134
+
135
+ def cal9
136
+ [-3, 0, 3].each do |offset_month|
137
+ origin_date = Date.today >> (offset_month)
138
+
139
+ print_3month_calendar(origin_date)
140
+ end
141
+ end
142
+
143
+ def print_3month_calendar(origin_date)
110
144
  table = Array.new(ROWS){
111
145
  Array.new(WEEK * MONTH + SPACE){|i|
112
146
  (i + 1) % 8 == 0 ? '' : ' '
@@ -114,16 +148,16 @@ module Xcal
114
148
  }
115
149
 
116
150
  today = Date.today
117
- last_month = today << 1
118
- next_month = today >> 1
151
+ last_month = origin_date << 1
152
+ next_month = origin_date >> 1
119
153
 
120
- fill_calendar(last_month.year, last_month.month, table, 0, japan_holidays, today)
121
- fill_calendar(today.year, today.month, table, 8, japan_holidays, today)
122
- fill_calendar(next_month.year, next_month.month, table, 16, japan_holidays, today)
154
+ fill_calendar(last_month.year, last_month.month, table, 0, @holidays, today)
155
+ fill_calendar(origin_date.year, origin_date.month, table, 8, @holidays, today)
156
+ fill_calendar(next_month.year, next_month.month, table, 16, @holidays, today)
123
157
 
124
158
  month_headers = [
125
159
  month_header(last_month.year, last_month.month),
126
- month_header(today.year, today.month),
160
+ month_header(origin_date.year, origin_date.month),
127
161
  month_header(next_month.year, next_month.month)
128
162
  ]
129
163
  puts month_headers.join(' ')
@@ -134,4 +168,18 @@ module Xcal
134
168
  puts row.join(' ')
135
169
  }
136
170
  end
171
+
172
+ def list_holidays(first, last)
173
+ holidays = (first..last).each_with_object([]){|date, memo|
174
+ y = date.year
175
+ m = date.month
176
+ d = date.day
177
+
178
+ memo << @holidays[y][m][d] if @holidays[y] && @holidays[y][m] && @holidays[y][m][d]
179
+ }
180
+
181
+ holidays.each{|holiday|
182
+ puts "#{holiday[:date].strftime("%Y-%m-%d")} (#{header[holiday[:date].wday]}) #{holiday[:summary]}"
183
+ }
184
+ end
137
185
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xcal
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xmisao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-03 00:00:00.000000000 Z
11
+ date: 2017-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: icalendar