tvtid 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/library/tvtid/client.rb +1 -0
- data/library/tvtid/schedule.rb +25 -0
- data/library/tvtid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea4bedf76b78e369cfac3ad2e67444f5172c64b0
|
4
|
+
data.tar.gz: 6c37d809faef50bd339f0678233744d9c554db91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bec9af98fa1f916b41a46946b35bef2a5b9feccef34d66a562aaf5975bd80c2911740d08ebe17575ac001839713695bfb44f5b94225846b5419835418ace21b
|
7
|
+
data.tar.gz: '093bb630fb49e60928a4219c27515d65d2f935ae23c364bed377115383f4e42246db53af4bcd34f1a047fadd91869c8de0a3dcdebf0b4e45b36431c5cd5c5202'
|
data/library/tvtid/client.rb
CHANGED
@@ -45,6 +45,7 @@ module TVTid
|
|
45
45
|
json_data.map do |schedule|
|
46
46
|
channel = channels.find{|channel| channel.id == schedule['id']}
|
47
47
|
programs = schedule['programs'].map{|program| Program.from_json program }
|
48
|
+
programs.sort!{|a, b| a.start_time <=> b.start_time }
|
48
49
|
|
49
50
|
Schedule.new channel, programs
|
50
51
|
end
|
data/library/tvtid/schedule.rb
CHANGED
@@ -10,5 +10,30 @@ module TVTid
|
|
10
10
|
@channel = channel
|
11
11
|
@programs = programs
|
12
12
|
end
|
13
|
+
|
14
|
+
# Get the previous, current and upcoming programs at a given `time`.
|
15
|
+
#
|
16
|
+
# @returns [previous<Array>, current<Program>, upcoming<Array>]
|
17
|
+
def at time
|
18
|
+
cur_idx = 0
|
19
|
+
|
20
|
+
@programs.each_with_index do |program, index|
|
21
|
+
if program.start_time <= time and program.stop_time >= time
|
22
|
+
cur_idx = index
|
23
|
+
break
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if cur_idx != 0
|
28
|
+
return @programs[0..cur_idx-1], @programs[cur_idx], @programs[cur_idx+1..-1]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the previous, current and upcoming programs.
|
33
|
+
#
|
34
|
+
# @see at
|
35
|
+
def current
|
36
|
+
self.at DateTime.now
|
37
|
+
end
|
13
38
|
end
|
14
39
|
end
|
data/library/tvtid/version.rb
CHANGED