dtv_tournaments 0.0.3 → 0.0.4
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 +8 -8
- data/.gitignore +1 -0
- data/dtv_tournaments.gemspec +1 -0
- data/lib/dtv_tournaments.rb +22 -0
- data/lib/dtv_tournaments/cache.rb +41 -0
- data/lib/dtv_tournaments/tournament.rb +29 -14
- data/lib/dtv_tournaments/version.rb +1 -1
- data/spec/cache_spec.rb +18 -0
- data/spec/tournament_spec.rb +56 -6
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjFhNGZlNDlkNTQ2MDE2MDIwZGVlODEwNzBlM2FlMjU2YjYyM2Y5MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTM2ZDExNTkyYTkzZTUyOTFiYWFlOTY1N2RjY2Q3YzhlN2RmNjczOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjBjZTQ4YzRhMTc5OTNjYWJmNDRkMDJlMDVhM2RmZmZlNWQ1OTg4ZWJkZmFm
|
10
|
+
NWMwNzU2ODMxYjY4YjBkYTcwZWYyNGRhNGEwZDJiYmY4NDc1MzVmYWQ5N2Ez
|
11
|
+
YjBlNzY1YTc5MjE1OTg1ZjBhZDVkYTA2NzQ3NjMzYjQyOGQ4Mzc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTA3YTY5ZTE1N2U4NzNhNjk5YTU1Njg0Y2Q1MzZjMWNhNjA0ZTNhYjAxN2Yw
|
14
|
+
NzhhM2U1ZTIyYzRjNDhlNzliZDQ5MjNkYWVlYTBjODM2MGE3YjFlMmViZmE5
|
15
|
+
MjU5ODhkNTM4MmRiODM4NzE5ZDc3YjNiNWU0NjVhMTVhMjlmYTg=
|
data/.gitignore
CHANGED
data/dtv_tournaments.gemspec
CHANGED
data/lib/dtv_tournaments.rb
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
require "redis"
|
2
|
+
|
1
3
|
require "dtv_tournaments/version"
|
2
4
|
require "dtv_tournaments/utilities"
|
5
|
+
require "dtv_tournaments/cache"
|
3
6
|
require "dtv_tournaments/tournament"
|
7
|
+
|
8
|
+
module DTVTournaments
|
9
|
+
def self.get number, rerun=false
|
10
|
+
if rerun
|
11
|
+
DTVTournaments::Tournament.new(number)
|
12
|
+
else
|
13
|
+
DTVTournaments.get_cached_tournament(number)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_cached_tournament(number)
|
18
|
+
cached = DTVTournaments.get_cache.get_by_number(number)
|
19
|
+
if cached.nil?
|
20
|
+
DTVTournaments.get(number, true)
|
21
|
+
else
|
22
|
+
cached
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'redis'
|
2
|
+
|
3
|
+
module DTVTournaments
|
4
|
+
class << self
|
5
|
+
attr_writer :cache_configuration, :cache
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.cache_configuration
|
9
|
+
reset_cache_config if @cache_configuration.nil?
|
10
|
+
@cache_configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.reset_cache_config
|
14
|
+
@cache_configuration = {:host => '127.0.0.1', :port => 6379, :db => 1}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configure_cache
|
18
|
+
yield(cache_configuration)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get_cache
|
22
|
+
@cache ||= Cache.new
|
23
|
+
end
|
24
|
+
|
25
|
+
class Cache < Struct.new(:redis)
|
26
|
+
def initialize
|
27
|
+
config = DTVTournaments.cache_configuration
|
28
|
+
@redis = Redis.new(config)
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_by_number(number)
|
32
|
+
data = @redis.get(number)
|
33
|
+
return nil if data.nil?
|
34
|
+
Tournament.deserialize(data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def set(tournament)
|
38
|
+
@redis.set(tournament.number, tournament.serialize)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -3,19 +3,20 @@ require 'mechanize'
|
|
3
3
|
module DTVTournaments
|
4
4
|
class Tournament
|
5
5
|
attr_accessor :number, :notes, :date, :time, :datetime, :street, :zip, :city, :kind, :page
|
6
|
-
def initialize number
|
7
|
-
@number = number
|
8
|
-
call
|
9
|
-
end
|
10
6
|
|
11
|
-
def
|
12
|
-
|
7
|
+
def initialize number, shouldCall=true
|
8
|
+
@number = number
|
9
|
+
call if shouldCall
|
13
10
|
end
|
14
11
|
|
15
|
-
def call
|
16
|
-
# TODO: Support cached option later
|
12
|
+
def call
|
17
13
|
get_result_page
|
18
14
|
extract_results
|
15
|
+
save_to_cache
|
16
|
+
end
|
17
|
+
|
18
|
+
def save_to_cache
|
19
|
+
DTVTournaments.get_cache.set(self)
|
19
20
|
end
|
20
21
|
|
21
22
|
def get_result_page
|
@@ -81,7 +82,6 @@ module DTVTournaments
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def get_time_from_big_tournament tournaments
|
84
|
-
|
85
85
|
times = tournaments.map do |single_tournament|
|
86
86
|
next_time = DTVTournaments::get_subelement_if_available(single_tournament, ".uhrzeit")
|
87
87
|
|
@@ -95,10 +95,25 @@ module DTVTournaments
|
|
95
95
|
index = get_index_of_marked_tournament tournaments
|
96
96
|
get_first_time_until(times, index)
|
97
97
|
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
98
|
|
102
|
-
|
99
|
+
def self.deserialize(data)
|
100
|
+
a = data.split('|')
|
101
|
+
datetime = a[2]
|
102
|
+
|
103
|
+
t = Tournament.new(a[0].to_i, false)
|
104
|
+
t.notes = a[1]
|
105
|
+
t.datetime = DateTime.parse(datetime)
|
106
|
+
t.time = Time.parse(datetime) - 60*60
|
107
|
+
t.date = Date.parse(datetime)
|
108
|
+
t.street = a[3]
|
109
|
+
t.zip = a[4]
|
110
|
+
t.city = a[5]
|
111
|
+
t.kind = a[6]
|
112
|
+
t
|
113
|
+
end
|
103
114
|
|
104
|
-
|
115
|
+
def serialize
|
116
|
+
"#{@number}|#{@notes}|#{@datetime.to_s}|#{@street}|#{@zip}|#{@city}|#{@kind}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/spec/cache_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe DTVTournaments::Cache do
|
3
|
+
before(:all) do
|
4
|
+
@cache = DTVTournaments.get_cache
|
5
|
+
end
|
6
|
+
it "should return the same as given in" do
|
7
|
+
t1 = DTVTournaments::Tournament.new(38542)
|
8
|
+
@cache.set(t1)
|
9
|
+
t2 = @cache.get_by_number(38542)
|
10
|
+
|
11
|
+
expect(t1.number).to eq(t2.number)
|
12
|
+
expect(t1.notes).to eq(t2.notes)
|
13
|
+
expect(t1.kind).to eq(t2.kind)
|
14
|
+
expect(t1.datetime.to_s).to eq(t2.datetime.to_s)
|
15
|
+
expect(t1.date.to_s).to eq(t2.date.to_s)
|
16
|
+
expect(t1.time.to_s).to eq(t2.time.to_s)
|
17
|
+
end
|
18
|
+
end
|
data/spec/tournament_spec.rb
CHANGED
@@ -3,7 +3,7 @@ describe DTVTournaments::Tournament do
|
|
3
3
|
describe "results" do
|
4
4
|
describe "large tournaments" do
|
5
5
|
before(:all) do
|
6
|
-
@t = DTVTournaments
|
6
|
+
@t = DTVTournaments.get(40472, true)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should have the right date" do
|
@@ -21,7 +21,7 @@ describe DTVTournaments::Tournament do
|
|
21
21
|
|
22
22
|
describe "small tournaments" do
|
23
23
|
before(:all) do
|
24
|
-
@t = DTVTournaments
|
24
|
+
@t = DTVTournaments.get(38542, true)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should have the right date" do
|
@@ -36,12 +36,62 @@ describe DTVTournaments::Tournament do
|
|
36
36
|
expect(@t.kind).to eq('HGR D ST')
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
describe "caching" do
|
41
|
+
it "should ask the cache if tournament would be fetched" do
|
42
|
+
DTVTournaments.should_receive(:get_cached_tournament).with(38542)
|
43
|
+
|
44
|
+
DTVTournaments.get(38542)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should fetch normally if not found in cache" do
|
48
|
+
cache = double('Cache', :get_by_number => nil)
|
49
|
+
|
50
|
+
DTVTournaments.should_receive(:get_cache).and_return(cache)
|
51
|
+
DTVTournaments::Tournament.should_receive(:new).with(38542)
|
52
|
+
|
53
|
+
DTVTournaments.get(38542)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should save to cache if not found in cache" do
|
57
|
+
cache = double('Cache', :get_by_number => nil)
|
58
|
+
cache.should_receive(:set)
|
59
|
+
DTVTournaments.should_receive(:get_cache).at_least(1).and_return(cache)
|
60
|
+
|
61
|
+
DTVTournaments.get(38542)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should save to cache if rerun is set" do
|
65
|
+
cache = double('Cache', :get_by_number => nil)
|
66
|
+
cache.should_receive(:set)
|
67
|
+
DTVTournaments.should_receive(:get_cache).and_return(cache)
|
68
|
+
|
69
|
+
DTVTournaments.get(38542, true)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not ask the cache if rerun is set" do
|
73
|
+
cache = double('Cache', :set => nil)
|
74
|
+
cache.should_not_receive(:get_by_number)
|
75
|
+
DTVTournaments.should_receive(:get_cache).and_return(cache)
|
76
|
+
|
77
|
+
DTVTournaments.get(38542, true)
|
78
|
+
end
|
79
|
+
end
|
39
80
|
end
|
40
81
|
|
41
82
|
describe "options" do
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
it "should
|
83
|
+
after(:each) do
|
84
|
+
DTVTournaments.reset_cache_config
|
85
|
+
end
|
86
|
+
it "should be possible to configure a redis cache" do
|
87
|
+
DTVTournaments.configure_cache do |config|
|
88
|
+
config[:host] = '10.0.1.42'
|
89
|
+
config[:port] = 6342
|
90
|
+
config[:db] = 15
|
91
|
+
end
|
92
|
+
Redis.should_receive(:new).with(:host => "10.0.1.42", :port => 6342, :db => 15)
|
93
|
+
|
94
|
+
DTVTournaments::Cache.new
|
95
|
+
end
|
46
96
|
end
|
47
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtv_tournaments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schmidt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: redis
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.7
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.7
|
83
97
|
description: This gem fetches the appsrv.tanzsport.de/dtv-webdbs/turnier/suche.spf
|
84
98
|
portal and gives all available informations about the tournaments
|
85
99
|
email:
|
@@ -96,9 +110,11 @@ files:
|
|
96
110
|
- Rakefile
|
97
111
|
- dtv_tournaments.gemspec
|
98
112
|
- lib/dtv_tournaments.rb
|
113
|
+
- lib/dtv_tournaments/cache.rb
|
99
114
|
- lib/dtv_tournaments/tournament.rb
|
100
115
|
- lib/dtv_tournaments/utilities.rb
|
101
116
|
- lib/dtv_tournaments/version.rb
|
117
|
+
- spec/cache_spec.rb
|
102
118
|
- spec/spec_helper.rb
|
103
119
|
- spec/tournament_spec.rb
|
104
120
|
homepage: https://github.com/DanielMSchmidt/dtv_tournaments
|
@@ -126,5 +142,6 @@ signing_key:
|
|
126
142
|
specification_version: 4
|
127
143
|
summary: A ruby gem for fetching tournaments from the dtv tournaments portal
|
128
144
|
test_files:
|
145
|
+
- spec/cache_spec.rb
|
129
146
|
- spec/spec_helper.rb
|
130
147
|
- spec/tournament_spec.rb
|