cal4near 0.1.3 → 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/exe/cal4 +14 -13
- data/lib/cal4near/version.rb +1 -1
- data/lib/cal4near.rb +15 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 962a769e590ce2126052259f29cb6388e0437a3bb7710d6af2352ba9390b9ba7
|
4
|
+
data.tar.gz: e6f4a4aef668039638293302e4fa8be1d2e8774fe9640dfcb4c158fae7175999
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c410224e01c9ada37128b56e5f6535d26fafe12099edccd8c76266e706020aa82b3f4c923950e05de7abef4e02104c67294e74dd516b5bc1ee8f60abd9e9e40
|
7
|
+
data.tar.gz: a33c7228f8b45b1d9d85427a7598ad1325c1c6ce07c8c666562c1c912e38544e11033b9e7b4c6ad7e1a09f346c74152dd5637e42be7a8283823de9a276f99e1a
|
data/exe/cal4
CHANGED
@@ -3,12 +3,12 @@ require "bundler/setup"
|
|
3
3
|
require "cal4near"
|
4
4
|
|
5
5
|
HELP_MSG =<<-MSG
|
6
|
-
usage: cal4 [free|busy] [-h]
|
6
|
+
usage: cal4 [ free, f | busy, b ] [ -h ]
|
7
7
|
|
8
|
-
free : Stdout free times from
|
9
|
-
busy : Stdout busy times from
|
8
|
+
free, f : Stdout free times from Google Calendar api
|
9
|
+
busy, b : Stdout busy times from Google Calendar api
|
10
10
|
|
11
|
-
-h :
|
11
|
+
-h : Show help
|
12
12
|
MSG
|
13
13
|
|
14
14
|
WRONG_ARG_ERR_MSG =<<-MSG
|
@@ -22,11 +22,12 @@ if ARGV.length > 0
|
|
22
22
|
return
|
23
23
|
when 'free', 'f'
|
24
24
|
msg = "free times"
|
25
|
-
times_info = Cal4near.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
times_info = Cal4near.free_busy_times
|
26
|
+
is_free = true
|
27
|
+
when 'busy', 'b'
|
28
|
+
msg = "busy times"
|
29
|
+
times_info = Cal4near.free_busy_times
|
30
|
+
is_free = false
|
30
31
|
else
|
31
32
|
puts WRONG_ARG_ERR_MSG
|
32
33
|
puts HELP_MSG
|
@@ -39,9 +40,9 @@ else
|
|
39
40
|
end
|
40
41
|
|
41
42
|
puts <<-MSG
|
42
|
-
|
43
|
-
#{msg}
|
44
|
-
|
43
|
+
----------------------------
|
44
|
+
#{msg} (9:00 - 19:00)
|
45
|
+
----------------------------
|
45
46
|
MSG
|
46
47
|
|
47
|
-
Cal4near.
|
48
|
+
puts Cal4near.format(times_info, is_free)
|
data/lib/cal4near/version.rb
CHANGED
data/lib/cal4near.rb
CHANGED
@@ -6,8 +6,6 @@ require "googleauth"
|
|
6
6
|
require "googleauth/stores/file_token_store"
|
7
7
|
require "date"
|
8
8
|
require "fileutils"
|
9
|
-
# require 'pry'
|
10
|
-
# require 'pry-byebug'
|
11
9
|
|
12
10
|
module Cal4near
|
13
11
|
class Error < StandardError; end
|
@@ -22,7 +20,7 @@ module Cal4near
|
|
22
20
|
SCOPE = Google::Apis::CalendarV3::AUTH_CALENDAR_READONLY
|
23
21
|
|
24
22
|
# 空き時間を検索する日時の範囲
|
25
|
-
START_DATE = DateTime.now
|
23
|
+
START_DATE = DateTime.now.next_day(1)
|
26
24
|
END_DATE = DateTime.now.next_day(30)
|
27
25
|
|
28
26
|
# 空き時間を検索する時間の範囲
|
@@ -53,11 +51,12 @@ module Cal4near
|
|
53
51
|
# @return [Hash]
|
54
52
|
# @example 返り値のサンプルは以下
|
55
53
|
# "2022-03-21"=> {"2022-03-21 09:00"=>{:free=>true}
|
56
|
-
def self.
|
54
|
+
def self.free_busy_times(
|
57
55
|
start_date = START_DATE,
|
58
56
|
end_date = END_DATE,
|
59
57
|
start_hour = START_HOUR,
|
60
|
-
end_hour = END_HOUR
|
58
|
+
end_hour = END_HOUR,
|
59
|
+
max_date_count = 100
|
61
60
|
)
|
62
61
|
busy_list = []
|
63
62
|
events(start_date, end_date).each do |event|
|
@@ -78,7 +77,9 @@ module Cal4near
|
|
78
77
|
# puts "Free time:"
|
79
78
|
|
80
79
|
result = {}
|
81
|
-
(start_date.to_date..end_date.to_date).each do |date|
|
80
|
+
(start_date.to_date..end_date.to_date).each.with_index(1) do |date, i|
|
81
|
+
break if i > max_date_count
|
82
|
+
|
82
83
|
result[date.strftime(DATE_FORMAT)] ||= {} # YYYY-MM-DD
|
83
84
|
|
84
85
|
start_work_time = Time.new(date.year, date.month, date.day, start_hour, 0, 0)
|
@@ -107,19 +108,19 @@ module Cal4near
|
|
107
108
|
result
|
108
109
|
end
|
109
110
|
|
110
|
-
# @param [Hash]
|
111
|
-
def self.
|
111
|
+
# @param [Hash] free_busy_times
|
112
|
+
def self.format(times_info, is_free = true)
|
112
113
|
result = times_info
|
113
114
|
wdays = %w(日 月 火 水 木 金 土)
|
114
115
|
# 出力
|
115
|
-
result.
|
116
|
+
date_time_info = result.map do |date, times|
|
116
117
|
min_time = max_time = nil
|
117
118
|
spans = []
|
118
119
|
times.each do |time, info|
|
119
120
|
time = DateTime.parse(time)
|
120
121
|
min_time ||= time
|
121
122
|
max_time = time
|
122
|
-
if info[:free]
|
123
|
+
if (is_free && info[:free]) || (!is_free && !info[:free])
|
123
124
|
next
|
124
125
|
else
|
125
126
|
if min_time && max_time && min_time < max_time
|
@@ -134,8 +135,11 @@ module Cal4near
|
|
134
135
|
end
|
135
136
|
|
136
137
|
tmp_date = Date.parse(date)
|
137
|
-
|
138
|
+
spans_text = spans.empty? ? "" : " #{spans.join(", ")}"
|
139
|
+
"#{tmp_date.strftime("%Y/%m/%d")}(#{wdays[tmp_date.wday]})#{spans_text}"
|
138
140
|
end
|
141
|
+
|
142
|
+
date_time_info.join("\n")
|
139
143
|
end
|
140
144
|
|
141
145
|
##
|