ellen-syoboi_calendar 0.0.1 → 0.0.2

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: 76860f9b7414a8f31229cfcc572588ac51b1a714
4
- data.tar.gz: 4d3c21a6e8ba0e35f407d69ae66c7f204172eb5e
3
+ metadata.gz: b5407684549c70fbee83244ff539c04a37c962ee
4
+ data.tar.gz: 0bdc13a03589da35e52cfa63811a6090d41bdbd8
5
5
  SHA512:
6
- metadata.gz: 37ba08772ec90e7cc41f58264c8f7cf7daa998ed7f0e157dc0d410d4b1107b00978a897810498f5f2cf8cc7929a6b1a2a6a53ec3e26daa521e41f741736fe22b
7
- data.tar.gz: f8dd18aa078c8d408d330abdad7431fbbda2ae5b0cd67b7bc657c8a1cc7598b5627723b393b9e4a7352607d0b3b68d6fb88dadf84fcb0f3eb6d5bd1d6b35476c
6
+ metadata.gz: 329582c7428aab4ee2b49ccf0540599f7bfc7b2ef89aea7aeb3bcbfaa4ad4826c0731ee966d76315e0598ac44c36890c46ffa141a37a83a13a8f1e04ec06a1e5
7
+ data.tar.gz: 8955e82270eca0749206c7d89cf9d5878e8871c3931e86fd99a249732227f3f6343f04967ca6fd5a353bc2a004351648d6f070f0495fa550220ef0fda4033ee8
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## 0.0.2
2
+ * Add SYOBOI_CALENDAR_CHANNEL_IDS ENV to filter programs
3
+ * Search in 04:00..28:00
4
+
5
+ ## 0.0.1
6
+ * 1st Release
data/README.md CHANGED
@@ -11,3 +11,6 @@ gem "ellen-syoboi_calendar"
11
11
  ```
12
12
  @ellen list anime
13
13
  ```
14
+
15
+ ## Screenshot
16
+ ![](https://raw.githubusercontent.com/r7kamura/ellen-syoboi_calendar/master/images/screenshot.gif)
Binary file
@@ -1,4 +1,6 @@
1
+ require "active_support/core_ext/enumerable"
1
2
  require "active_support/core_ext/numeric/time"
3
+ require "active_support/core_ext/date"
2
4
  require "active_support/core_ext/time"
3
5
 
4
6
  module Ellen
@@ -6,15 +8,25 @@ module Ellen
6
8
  class SyoboiCalendar < Base
7
9
  on(/list anime\z/, name: "list", description: "List today's anime")
8
10
 
11
+ env :SYOBOI_CALENDAR_CHANNEL_IDS, "Comma-separated channel IDs to filter programs", optional: true
12
+
9
13
  def list(message)
10
- message.reply(descriptions.join("\n"))
14
+ message.reply(description)
11
15
  end
12
16
 
13
17
  private
14
18
 
19
+ def description
20
+ if descriptions.empty?
21
+ "No programs found"
22
+ else
23
+ descriptions.join("\n")
24
+ end
25
+ end
26
+
15
27
  def descriptions
16
- programs_sorted_by_started_at.map do |program|
17
- "#{program[:started_at].strftime("%Y-%m-%d %H:%M")} #{titles_by_id[program[:title_id]][:title]} #{program[:count]}"
28
+ @descriptions ||= programs_sorted_by_started_at.map do |program|
29
+ "#{program.started_at_in_string} #{titles_index_by_id[program.title_id].title} #{program.count}"
18
30
  end
19
31
  end
20
32
 
@@ -22,19 +34,17 @@ module Ellen
22
34
  @client ||= ::SyoboiCalendar::Client.new
23
35
  end
24
36
 
25
- def titles_by_id
26
- @titles_by_id ||= titles.inject({}) do |table, title|
27
- table.merge(title[:id] => title)
28
- end
37
+ def titles_index_by_id
38
+ @titles_by_id ||= titles.index_by(&:id)
29
39
  end
30
40
 
31
41
  def titles
32
42
  [get_titles.TitleLookupResponse.TitleItems.TitleItem].flatten.map do |title|
33
- {
43
+ Ellen::SyoboiCalendar::Title.new(
34
44
  id: title.id,
35
45
  title: title.Title,
36
46
  short_title: title.ShortTitle,
37
- }
47
+ )
38
48
  end
39
49
  end
40
50
 
@@ -50,46 +60,62 @@ module Ellen
50
60
 
51
61
  def title_ids_in_programs
52
62
  programs.map do |program|
53
- program[:title_id]
63
+ program.title_id
54
64
  end
55
65
  end
56
66
 
57
67
  def programs_sorted_by_started_at
58
- programs.sort_by do |program|
59
- program[:started_at]
60
- end
68
+ programs.sort_by(&:started_at)
61
69
  end
62
70
 
63
71
  def programs
64
- @programs ||= [get_programs.ProgLookupResponse.ProgItems.ProgItem].flatten.map do |program|
65
- {
72
+ @programs ||= get_programs.map do |program|
73
+ Ellen::SyoboiCalendar::Program.new(
66
74
  count: program.Count,
67
75
  channel_id: program.ChID,
68
76
  sub_title: program.STSubTitle,
69
77
  title_id: program.TID,
70
- started_at: Time.parse(program.StTime),
71
- finished_at: Time.parse(program.EdTime),
72
- }
78
+ started_at: program.StTime,
79
+ finished_at: program.EdTime,
80
+ )
73
81
  end
74
82
  end
75
83
 
76
84
  def get_programs
77
- client.programs(program_options)
85
+ if items = client.programs(program_options).ProgLookupResponse.ProgItems
86
+ [items.ProgItem].flatten.compact
87
+ else
88
+ []
89
+ end
78
90
  end
79
91
 
80
92
  def program_options
81
93
  {
82
94
  played_from: played_from,
83
95
  played_to: played_to,
84
- }
96
+ channel_id: channel_ids,
97
+ }.reject {|key, value| value.nil? }
98
+ end
99
+
100
+ def channel_ids
101
+ ENV["SYOBOI_CALENDAR_CHANNEL_IDS"]
102
+ end
103
+
104
+ def now
105
+ @now ||= Time.now
85
106
  end
86
107
 
87
108
  def played_from
88
- Time.now
109
+ now
89
110
  end
90
111
 
112
+ # 04:00 ~ 28:00
91
113
  def played_to
92
- Time.now.end_of_day
114
+ if now.hour >= 4
115
+ now.tomorrow.beginning_of_day + 4.hour
116
+ else
117
+ now.beginning_of_day + 4.hour
118
+ end
93
119
  end
94
120
  end
95
121
  end
@@ -0,0 +1,22 @@
1
+ module Ellen
2
+ module SyoboiCalendar
3
+ class Program < Record
4
+
5
+ property(
6
+ :channel_id,
7
+ :count,
8
+ :sub_title,
9
+ :title_id,
10
+ )
11
+
12
+ time_property(
13
+ :finished_at,
14
+ :started_at,
15
+ )
16
+
17
+ def started_at_in_string
18
+ started_at.strftime("%Y-%m-%d %H:%M")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ module Ellen
2
+ module SyoboiCalendar
3
+ class Record
4
+ class << self
5
+ def property(*names)
6
+ names.each do |name|
7
+ define_method(name) do
8
+ properties[name]
9
+ end
10
+ end
11
+ end
12
+
13
+ def time_property(*names)
14
+ names.each do |name|
15
+ define_method(name) do
16
+ Time.parse(properties[name])
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ attr_reader :properties
23
+
24
+ def initialize(properties)
25
+ @properties = properties
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module Ellen
2
+ module SyoboiCalendar
3
+ class Title < Record
4
+
5
+ property(
6
+ :id,
7
+ :short_title,
8
+ :title,
9
+ )
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Ellen
2
2
  module SyoboiCalendar
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -3,3 +3,6 @@ require "syoboi_calendar"
3
3
 
4
4
  require "ellen/handlers/syoboi_calendar"
5
5
  require "ellen/syoboi_calendar/version"
6
+ require "ellen/syoboi_calendar/record"
7
+ require "ellen/syoboi_calendar/program"
8
+ require "ellen/syoboi_calendar/title"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ellen-syoboi_calendar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
@@ -144,13 +144,18 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".gitignore"
147
+ - CHANGELOG.md
147
148
  - Gemfile
148
149
  - LICENSE.txt
149
150
  - README.md
150
151
  - Rakefile
151
152
  - ellen-syoboi_calendar.gemspec
153
+ - images/screenshot.gif
152
154
  - lib/ellen/handlers/syoboi_calendar.rb
153
155
  - lib/ellen/syoboi_calendar.rb
156
+ - lib/ellen/syoboi_calendar/program.rb
157
+ - lib/ellen/syoboi_calendar/record.rb
158
+ - lib/ellen/syoboi_calendar/title.rb
154
159
  - lib/ellen/syoboi_calendar/version.rb
155
160
  - spec/ellen/handlers/syoboi_calendar_spec.rb
156
161
  - spec/spec_helper.rb