tvtid 0.1 → 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: a4fed7edb8d062f0e970ea68728474290b4c4f0c
4
- data.tar.gz: c54fd7e6cceb49c6c659a8362adc1d88cede8bbe
3
+ metadata.gz: ea4bedf76b78e369cfac3ad2e67444f5172c64b0
4
+ data.tar.gz: 6c37d809faef50bd339f0678233744d9c554db91
5
5
  SHA512:
6
- metadata.gz: f0899ab3cbd46626d7c1214b3a6c6912b0d6db747f3177d669b88d9c041d47bf62346b05f79f89c3ee5ed422ccde58b1237de2fc41a31c261956c3ddd0291ac5
7
- data.tar.gz: b9d639a7c57e2bc49d3c37db1a1c0189e5fac2eb4a5b577a77e3f9a83b4a7aeb13b8464db7b274f3f7193758336f302dab7d3e67c67a6be72b64852e65e66923
6
+ metadata.gz: 1bec9af98fa1f916b41a46946b35bef2a5b9feccef34d66a562aaf5975bd80c2911740d08ebe17575ac001839713695bfb44f5b94225846b5419835418ace21b
7
+ data.tar.gz: '093bb630fb49e60928a4219c27515d65d2f935ae23c364bed377115383f4e42246db53af4bcd34f1a047fadd91869c8de0a3dcdebf0b4e45b36431c5cd5c5202'
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TVTid
2
- Version = '0.1'
2
+ Version = '0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tvtid
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Kroman