kandianying 0.0.6 → 0.0.7
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/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/README.md +12 -2
- data/bin/kandianying +6 -5
- data/lib/kandianying/version.rb +2 -2
- data/lib/kandianying/vieshow.rb +3 -42
- data/lib/kandianying/vieshow_scrape.rb +49 -0
- data/lib/kandianying/vieshow_search.rb +49 -0
- data/spec/fixtures/vcr_cassettes/vieshow_name_05.yml +133 -114
- data/spec/fixtures/vcr_cassettes/vieshow_name_12.yml +82 -77
- data/spec/fixtures/vcr_cassettes/vieshow_table_05.yml +133 -114
- data/spec/fixtures/vcr_cassettes/vieshow_table_12.yml +82 -77
- data/spec/fixtures/vieshow_name_05.yml +7 -7
- data/spec/fixtures/vieshow_name_12.yml +5 -6
- data/spec/fixtures/vieshow_table_05.yml +308 -59
- data/spec/fixtures/vieshow_table_12.yml +248 -48
- data/spec/vieshow_spec.rb +84 -7
- metadata +4 -2
data/spec/vieshow_spec.rb
CHANGED
@@ -4,6 +4,18 @@ TEST_SITES = %w(05 12)
|
|
4
4
|
FAIL_SITES = %w(0 16)
|
5
5
|
TEST_INFO = %w(name table)
|
6
6
|
FIXTURES = './spec/fixtures/vieshow_'
|
7
|
+
MONTHS = Date::ABBR_MONTHNAMES.compact
|
8
|
+
DAYS = Date::ABBR_DAYNAMES
|
9
|
+
PARTIAL_NAME = 4..10
|
10
|
+
HOUR_MIN = 11..15
|
11
|
+
AN_HOUR = 1 / 24.to_f
|
12
|
+
MIDNIGHT = %w(00 01 02 03)
|
13
|
+
TAIWAN_TIME = '+8'
|
14
|
+
GIVEN_DAY = (0..2).to_a
|
15
|
+
A_TO_Z = 'A'..'Z'
|
16
|
+
MAX_ALPHABET = 26
|
17
|
+
HOUR_PART = 0..1
|
18
|
+
ADD_24 = 24
|
7
19
|
|
8
20
|
describe 'Get film information' do
|
9
21
|
TEST_SITES.each do |site|
|
@@ -14,16 +26,81 @@ describe 'Get film information' do
|
|
14
26
|
site_info = yml_load("#{FIXTURES}#{t}_#{site}.yml")
|
15
27
|
compare = t == TEST_INFO[0] ? cinema.movie_names : cinema.movie_table
|
16
28
|
site_info.must_equal compare
|
17
|
-
end
|
18
|
-
|
29
|
+
end; end; end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'Get show times for a film' do
|
34
|
+
TEST_SITES.each do |site|
|
35
|
+
it 'should get viewing times for this film' do
|
36
|
+
VCR.use_cassette("vieshow_table_#{site}") do
|
37
|
+
cinema = HsinChuMovie::Vieshow.new(site.to_i)
|
38
|
+
one_movie = yml_load("#{FIXTURES}name_#{site}.yml").sample[PARTIAL_NAME]
|
39
|
+
# Films are saved as UPPERCASE but search should pass any case
|
40
|
+
cinema.film_times(one_movie.downcase).each do |film, date_times|
|
41
|
+
film.must_include one_movie
|
42
|
+
date_times.keys.each do |date|
|
43
|
+
words_in_date = date.split
|
44
|
+
MONTHS.must_include words_in_date.first
|
45
|
+
DAYS.must_include words_in_date.last
|
46
|
+
end; end; end
|
19
47
|
end
|
20
48
|
end
|
49
|
+
TEST_SITES.each do |site|
|
50
|
+
it 'should return empty array for random string' do
|
51
|
+
VCR.use_cassette("vieshow_table_#{site}") do
|
52
|
+
cinema = HsinChuMovie::Vieshow.new(site.to_i)
|
53
|
+
one_movie = (PARTIAL_NAME).map { A_TO_Z.to_a[rand(MAX_ALPHABET)] }.join
|
54
|
+
cinema.film_times(one_movie).must_be_empty
|
55
|
+
end; end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'Get films after a given time on given day' do
|
60
|
+
TEST_SITES.each do |site|
|
61
|
+
it "should only return films after a time for #{site}" do
|
62
|
+
VCR.use_cassette("vieshow_table_#{site}") do
|
63
|
+
cinema = HsinChuMovie::Vieshow.new(site.to_i)
|
64
|
+
time = DateTime.now.new_offset(TAIWAN_TIME)
|
65
|
+
time += GIVEN_DAY.sample
|
66
|
+
time_s = time.to_s
|
67
|
+
day_films = cinema.films_on_day(time_s)
|
68
|
+
after_films = cinema.films_after_time(time_s)
|
69
|
+
# comparison_time is an hour earlier than specified time
|
70
|
+
comparison_time = (time - AN_HOUR).to_s[HOUR_MIN]
|
71
|
+
day_films.each do |film, date_times|
|
72
|
+
date_times.each do |date, show_times|
|
73
|
+
if after_films[film].nil?
|
74
|
+
# If empty, all show times must be less than comparison time
|
75
|
+
show_times.each do |show_time|
|
76
|
+
show_time.must_be :<, comparison_time
|
77
|
+
end
|
78
|
+
else
|
79
|
+
after_show_times = after_films[film][date]
|
80
|
+
after_show_times.each do |ast|
|
81
|
+
# On day show times must include after request show times
|
82
|
+
show_times.must_include ast
|
83
|
+
# After show times must be greater than comparison time
|
84
|
+
if (ast < comparison_time) &&
|
85
|
+
(MIDNIGHT.include? ast[HOUR_PART])
|
86
|
+
# Movies airing from midnight onwards are group with past day
|
87
|
+
ast[HOUR_PART] = "#{ast[HOUR_PART].to_i + ADD_24}"
|
88
|
+
end
|
89
|
+
ast.must_be :>=, comparison_time
|
90
|
+
end
|
91
|
+
show_times -= after_films[film][date]
|
92
|
+
# Any show time not returned must be less than comparison time
|
93
|
+
show_times.each do |show_time|
|
94
|
+
show_time.must_be :<, comparison_time
|
95
|
+
end
|
96
|
+
end; end; end; end; end
|
97
|
+
end
|
21
98
|
end
|
22
99
|
|
23
100
|
describe 'Outside of 1 and 14 must fail' do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
101
|
+
FAIL_SITES.each do |site|
|
102
|
+
it "must fail for #{site}" do
|
103
|
+
proc { HsinChuMovie::Vieshow.new(site.to_i) }.must_raise RuntimeError
|
104
|
+
end
|
105
|
+
end
|
29
106
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kandianying
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stonegold546
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: minitest
|
@@ -106,6 +106,8 @@ files:
|
|
106
106
|
- lib/kandianying/ambassador.rb
|
107
107
|
- lib/kandianying/version.rb
|
108
108
|
- lib/kandianying/vieshow.rb
|
109
|
+
- lib/kandianying/vieshow_scrape.rb
|
110
|
+
- lib/kandianying/vieshow_search.rb
|
109
111
|
- spec/ambassador_spec.rb
|
110
112
|
- spec/fixtures/ambassador_name_38897fa9-094f-4e63-9d6d-c52408438cb6.yml
|
111
113
|
- spec/fixtures/ambassador_table_38897fa9-094f-4e63-9d6d-c52408438cb6.yml
|