dblugeon-rb-eyetv 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/eyetv.rb CHANGED
@@ -25,14 +25,18 @@ module EyeTV
25
25
  chans
26
26
  end
27
27
 
28
- def programs
28
+ #return program list, the only_future option indiquate if the future programs must be returned
29
+ def programs(only_future = true)
29
30
  programs_tab = []
30
31
  @instance.programs.get.each do |prog|
31
- programs_tab.push(Program.new(prog))
32
+ if !only_future or prog.start_time.get > Time.now
33
+ programs_tab.push(Program.new(prog))
34
+ end
32
35
  end
33
36
  programs_tab
34
37
  end
35
38
 
39
+ #return recording list
36
40
  def recordings
37
41
  recordings =[]
38
42
  @instance.recordings.get.each do |recording|
@@ -62,6 +66,7 @@ module EyeTV
62
66
  @instance.is_recording.get
63
67
  end
64
68
 
69
+ #return channel list
65
70
  def current_channel_number
66
71
  @intance.current_channel.get
67
72
  end
@@ -80,8 +85,56 @@ module EyeTV
80
85
  end
81
86
  end
82
87
  end
88
+
89
+ #create a program with options
90
+ #a nil option launch a live record
91
+ #example :
92
+ #a = EyeTV.new()
93
+ #p = a.make_program(:channel_number => 3, :start_time => Time.now + 120 seconds, :title => "Knight Rider", :duration => 3600, :quality => :hight)
94
+ #return an Program instance
95
+ #throw a ConflictProgramException if there is a "time conflict" with the :start_time and the :duration option
96
+
97
+ def make_program(options = {})
98
+ program = check_program(options)
99
+ if program != nil
100
+ puts "program = #{program.to_s}"
101
+ raise ConflictProgramException.new(program)
102
+ end
103
+ record = Program.new(@instance.make(:new =>:program, :with_properties => options))
104
+ end
105
+
106
+ #check options for make a program
107
+ #return an program instance if a conflict is detected
108
+ #if no conflict founded, return nil
109
+
110
+ def check_program(options={})
111
+ if(options[:duration] == nil)
112
+ options[:duration] = 10800
113
+ end
114
+ if(options[:start_time] == nil)
115
+ options[:start_time] = Time.now
116
+ end
117
+ res = nil
118
+ programs(true).each do |prog|
119
+ if(res == nil and prog.conflict?(options[:start_time], options[:duration]))
120
+ res = prog
121
+ end
122
+ end
123
+ res
124
+ end
125
+ end
126
+
127
+ #Exception can be throw by the make_program from EyeTV class
128
+ class ConflictProgramException < Exception
129
+ #return the program in conflict
130
+ attr_reader :program_exist
131
+
132
+ def initialize(program)
133
+ program_exist = program
134
+ end
83
135
  end
84
136
 
137
+
85
138
  if __FILE__ == $0
86
139
  puts "start Eyetv"
87
140
  etv = EyeTV.new
data/lib/program.rb CHANGED
@@ -32,6 +32,21 @@ module EyeTV
32
32
  @program_ref.duration.set(new_duration)
33
33
  end
34
34
 
35
+ #calculate the end time of program
36
+ def end_time
37
+ start_time + duration
38
+ end
39
+
40
+ #test if the parameters enter in conflict with a program instance
41
+ def conflict?(test_start_time, nduration)
42
+ nend_time = test_start_time + nduration
43
+ if nend_time < start_time or end_time < test_start_time
44
+ conflict = false
45
+ else
46
+ conflict = true
47
+ end
48
+ end
49
+
35
50
  def title
36
51
  @program_ref.title.get
37
52
  end
@@ -53,7 +68,12 @@ module EyeTV
53
68
  end
54
69
 
55
70
  def channel_number=(new_channel_number)
56
- @program_ref.channel_number.set(new_channel_number)
71
+ old_value = channel_number
72
+ @program_ref.channel_number.set(new_channel_number.to_i)
73
+ if(channel_number == 0)
74
+ channel_number = old_value
75
+ raise "unknow channel #{new_channel_number}"
76
+ end
57
77
  end
58
78
 
59
79
  def self.input_sources_possible
@@ -65,7 +85,7 @@ module EyeTV
65
85
  end
66
86
 
67
87
  def input_source=(new_input_source)
68
- raise "bad value for input_source" if not @@input_sources_possible.include?(new_input_source.to_sym)
88
+ raise "bad value for input_source" if !new_input_source.respond_to?(:to_sym) or not @@input_sources_possible.include?(new_input_source.to_sym)
69
89
  @program_ref.input_source.set(new_input_source.to_sym)
70
90
  end
71
91
 
@@ -78,7 +98,7 @@ module EyeTV
78
98
  end
79
99
 
80
100
  def repeats=(new_repeats)
81
- raise "bad value for repeats" if not @@repeats_possible.include?(new_repeats.to_sym)
101
+ raise "bad value for repeats" if !new_repeats.respond_to?(:to_sym) or not @@repeats_possible.include?(new_repeats.to_sym)
82
102
  @program_ref.repeats.set(new_repeats.to_sym)
83
103
  end
84
104
 
@@ -91,7 +111,7 @@ module EyeTV
91
111
  end
92
112
 
93
113
  def quality=(new_quality)
94
- raise "bad value for quality" if not @@qualities_possible.include?(new_quality.to_sym)
114
+ raise "bad value for quality" if !new_quality.respond_to?(:to_sym) or not @@qualities_possible.include?(new_quality.to_sym)
95
115
  @program_ref.quality.set(new_quality.to_sym)
96
116
  end
97
117
 
data/lib/recording.rb CHANGED
@@ -86,6 +86,14 @@ module EyeTV
86
86
  @recording_ref.name.set(value)
87
87
  end
88
88
 
89
+ def episode
90
+ name
91
+ end
92
+
93
+ def episode=(value)
94
+ self.name = value
95
+ end
96
+
89
97
  def uid
90
98
  @recording_ref.unique_ID.get
91
99
  end
data/rb-eyetv.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rb-eyetv}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["dblugeon"]
12
- s.date = %q{2009-09-07}
12
+ s.date = %q{2009-09-10}
13
13
  s.description = %q{
14
14
  This library provides ruby classes to control the EyeTV Application.
15
15
  You can launch the EyeTV apllication, explore recordings, channels or
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/recording.rb",
34
34
  "rb-eyetv.gemspec",
35
35
  "test/eyetv_test.rb",
36
+ "test/program_test.rb",
36
37
  "test/test_helper.rb"
37
38
  ]
38
39
  s.homepage = %q{http://github.com/dblugeon/rb-eyetv}
@@ -42,6 +43,7 @@ Gem::Specification.new do |s|
42
43
  s.summary = %q{This library provides ruby classes to control the EyeTV Application}
43
44
  s.test_files = [
44
45
  "test/eyetv_test.rb",
46
+ "test/program_test.rb",
45
47
  "test/test_helper.rb"
46
48
  ]
47
49
 
data/test/eyetv_test.rb CHANGED
@@ -5,6 +5,12 @@ class RbEyetvTest < Test::Unit::TestCase
5
5
  context "EyeTV application" do
6
6
  setup do
7
7
  @instance = EyeTV::EyeTV.new
8
+ if @instance.programs(true).empty?
9
+ @program_test = @instance.make_program({:start_time => Time.now + 3600, :duration => 3600, :title => "program unit test"})
10
+ @clean_program = true
11
+ else
12
+ @program_test = @instance.programs(true)[0]
13
+ end
8
14
  end
9
15
  should "not recording" do
10
16
  assert !(@instance.is_recording?)
@@ -33,5 +39,23 @@ class RbEyetvTest < Test::Unit::TestCase
33
39
  assert program.instance_of?(EyeTV::Program), "actual class = #{program.class.to_s}"
34
40
  end
35
41
  end
42
+
43
+ should "check check_program method with conflict program" do
44
+ assert_not_nil @instance.check_program({:start_time=>@program_test.start_time, :duration=>@program_test.duration})
45
+ end
46
+
47
+ should "check check_program method without conflict program" do
48
+ tmp_progs = @instance.programs(true).sort do |prog|
49
+ prog.start_time
50
+ end
51
+ prog = tmp_progs.last
52
+ assert_nil @instance.check_program({:start_time => prog.end_time + 200, :duration => prog.duration})
53
+ end
54
+
55
+ teardown do
56
+ if @clean_program
57
+ @program_test.delete
58
+ end
59
+ end
36
60
  end
37
61
  end
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+ include EyeTV
3
+
4
+ class RbProgramTest < Test::Unit::TestCase
5
+ context "EyeTV Program" do
6
+ setup do
7
+ @instance = EyeTV::EyeTV.new
8
+ if @instance.programs(true).empty?
9
+ @program_test = @instance.make_program({:start_time => Time.now + 3600, :duration => 3600, :title => "program unit test"})
10
+ @clean_program = true
11
+ else
12
+ @program_test = @instance.programs(true)[0]
13
+ end
14
+ end
15
+
16
+ should "test raise exception in input_source= method" do
17
+ assert_raise RuntimeError do
18
+ @program_test.input_source = DateTime.new
19
+ end
20
+ end
21
+
22
+ should "test raise exception in repeats= method" do
23
+ assert_raise RuntimeError do
24
+ @program_test.repeats = "never1"
25
+ end
26
+ end
27
+
28
+ should "test raise exception in quality= method" do
29
+ assert_raise RuntimeError do
30
+ @program_test.quality = "hight2"
31
+ end
32
+ end
33
+
34
+ should "test raise exception in start_time= method" do
35
+ assert_raise RuntimeError do
36
+ @program_test.start_time = DateTime.new
37
+ end
38
+ end
39
+
40
+ should "test raise exception in channel_number= method with string" do
41
+ assert_raise RuntimeError do
42
+ @program_test.channel_number = "sqdqs"
43
+ end
44
+ end
45
+
46
+ should "test raise exception in channel_number= method with 12000 channel" do
47
+ assert_raise RuntimeError do
48
+ @program_test.channel_number = "12000"
49
+ end
50
+ end
51
+
52
+ should "end_time must be equals to start_time + duration" do
53
+ assert_equal (@program_test.start_time + @program_test.duration), @program_test.end_time
54
+ end
55
+
56
+ should "program must conflict" do
57
+ test_start_time = @program_test.start_time + 200
58
+ duration = 1000
59
+
60
+ assert @program_test.conflict?(test_start_time, duration)
61
+
62
+ test_start_time = @program_test.start_time - 100
63
+
64
+ assert @program_test.conflict?(test_start_time, duration)
65
+
66
+ test_start_time = @program_test.end_time - 250
67
+
68
+ assert @program_test.conflict?(test_start_time, duration)
69
+ end
70
+
71
+ should "program should not conflict" do
72
+ test_start_time = @program_test.start_time - 1500
73
+ duration = 1000
74
+
75
+ assert !@program_test.conflict?(test_start_time, duration)
76
+
77
+ test_start_time = @program_test.end_time + 500
78
+ end
79
+
80
+ teardown do
81
+ if @clean_program
82
+ @program_test.delete
83
+ end
84
+ end
85
+ end
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dblugeon-rb-eyetv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - dblugeon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-07 00:00:00 -07:00
12
+ date: 2009-09-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -54,10 +54,10 @@ files:
54
54
  - lib/recording.rb
55
55
  - rb-eyetv.gemspec
56
56
  - test/eyetv_test.rb
57
+ - test/program_test.rb
57
58
  - test/test_helper.rb
58
59
  has_rdoc: false
59
60
  homepage: http://github.com/dblugeon/rb-eyetv
60
- licenses:
61
61
  post_install_message:
62
62
  rdoc_options:
63
63
  - --charset=UTF-8
@@ -78,10 +78,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  requirements: []
79
79
 
80
80
  rubyforge_project:
81
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.2.0
82
82
  signing_key:
83
83
  specification_version: 3
84
84
  summary: This library provides ruby classes to control the EyeTV Application
85
85
  test_files:
86
86
  - test/eyetv_test.rb
87
+ - test/program_test.rb
87
88
  - test/test_helper.rb