dtv_tournaments 0.0.4 → 0.1.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjFhNGZlNDlkNTQ2MDE2MDIwZGVlODEwNzBlM2FlMjU2YjYyM2Y5MQ==
4
+ MWE3OWJkNDAyYjFkNDA5NGFhZTkyMTgyZGM0N2RmZWFkOTE1MDMzMw==
5
5
  data.tar.gz: !binary |-
6
- NTM2ZDExNTkyYTkzZTUyOTFiYWFlOTY1N2RjY2Q3YzhlN2RmNjczOQ==
6
+ ZjBlNTZhNmU4N2M3YWM5NGE1N2VhMjJkNzc2MDNjZjg0M2FjOTk5NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjBjZTQ4YzRhMTc5OTNjYWJmNDRkMDJlMDVhM2RmZmZlNWQ1OTg4ZWJkZmFm
10
- NWMwNzU2ODMxYjY4YjBkYTcwZWYyNGRhNGEwZDJiYmY4NDc1MzVmYWQ5N2Ez
11
- YjBlNzY1YTc5MjE1OTg1ZjBhZDVkYTA2NzQ3NjMzYjQyOGQ4Mzc=
9
+ NWZmMjA2ZTYyOWIxODNiM2ZmYjQ5N2IyZGZjN2FiZDI2ZWY1MWNjOGUyNzkx
10
+ YTI1ZDA5ZWVhZTZmMzBiZDhiY2RkNDUyNGVjODUyYjZmZjNlZGMwZWVmNjQz
11
+ NDYwMGVjMmViMjJiNzkwYjVkYThlNjFkM2I4NTkwYWNkOTlkYjE=
12
12
  data.tar.gz: !binary |-
13
- ZTA3YTY5ZTE1N2U4NzNhNjk5YTU1Njg0Y2Q1MzZjMWNhNjA0ZTNhYjAxN2Yw
14
- NzhhM2U1ZTIyYzRjNDhlNzliZDQ5MjNkYWVlYTBjODM2MGE3YjFlMmViZmE5
15
- MjU5ODhkNTM4MmRiODM4NzE5ZDc3YjNiNWU0NjVhMTVhMjlmYTg=
13
+ YjdmN2I4ZTRhZWFjYmZkODc2MmZlMzA3ODI3ZmU2NjI1YzEwZGU2YTZjMTcz
14
+ YmQwOGExOGFhMTYyNDA5ZGI3YmM5ZDBiMzc2OTk0ZDBhNGJjMTk0MjExZDZj
15
+ ZDYxNTY3MzQ2MTZjYzBiNDkzMzk4MDI4MzMyOGQ1YWM0YjVkZTk=
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Call ``DtvTournaments::Tournament.new(number)`` to get an tournament instance with the the attributes
25
+ Call ``DtvTournaments.get(number)`` to get an tournament instance with the the attributes
26
26
 
27
27
  - number
28
28
  - date / time / datetime
@@ -36,9 +36,19 @@ It provides also the methods
36
36
 
37
37
  - rerun (to rerun the fetching process and update the cache)
38
38
 
39
+ ### Caching
40
+ To configure caching do
41
+
42
+ ```ruby
43
+ DTVTournaments.configure_cache do |config|
44
+ config[:active] = true
45
+ config[:host] = '10.0.1.42'
46
+ config[:port] = 6342
47
+ config[:db] = 15
48
+ end
49
+ ```
39
50
 
40
51
  ## Todos
41
- - fix that street and city is found by searching at the all tournaments page for the date and search there for the given number
42
52
  - add tournament specific methods (is placing, get points, ...)
43
53
 
44
54
 
@@ -11,7 +11,7 @@ module DTVTournaments
11
11
  end
12
12
 
13
13
  def self.reset_cache_config
14
- @cache_configuration = {:host => '127.0.0.1', :port => 6379, :db => 1}
14
+ @cache_configuration = {:host => '127.0.0.1', :port => 6379, :db => 1, :active => false}
15
15
  end
16
16
 
17
17
  def self.configure_cache
@@ -25,17 +25,23 @@ module DTVTournaments
25
25
  class Cache < Struct.new(:redis)
26
26
  def initialize
27
27
  config = DTVTournaments.cache_configuration
28
- @redis = Redis.new(config)
28
+ active = config.delete(:active)
29
+
30
+ @redis = Redis.new(config) if active
29
31
  end
30
32
 
31
33
  def get_by_number(number)
32
- data = @redis.get(number)
34
+ data = @redis.get(number) unless @redis.nil?
33
35
  return nil if data.nil?
34
- Tournament.deserialize(data)
36
+ Tournament.deserialize(Cache.toDataArray(data))
37
+ end
38
+
39
+ def self.toDataArray(data)
40
+ data.split('|')
35
41
  end
36
42
 
37
43
  def set(tournament)
38
- @redis.set(tournament.number, tournament.serialize)
44
+ @redis.set(tournament.number, tournament.serialize) unless @redis.nil?
39
45
  end
40
46
  end
41
47
  end
@@ -37,7 +37,7 @@ module DTVTournaments
37
37
  extract_kind
38
38
  extract_notes
39
39
  extract_location
40
- extract_time
40
+ parse_time(extract_date, extract_time)
41
41
  end
42
42
 
43
43
  def extract_kind
@@ -49,18 +49,22 @@ module DTVTournaments
49
49
  end
50
50
 
51
51
  def extract_location
52
- # TODO
52
+ @zip = @page.search('.ort strong').text.gsub!(/\D|\s/, "").to_i
53
+ @city = @page.search('.ort strong').text.gsub!(/\d|\s/, "")
54
+ @street = @page.search('.ort').to_html.split('<br>')[1].strip
53
55
  end
54
56
 
55
57
  def extract_time
56
58
  if page.search(".markierung .uhrzeit").first.text.empty?
57
59
  # This tournament is a big one
58
- time = get_time_from_big_tournament(page.search(".turniere tr"))
60
+ get_time_from_big_tournament(page.search(".turniere tr"))
59
61
  else
60
- time = page.search(".markierung .uhrzeit").text.scan(/\d{1,2}:\d{2}/).first
62
+ page.search(".markierung .uhrzeit").text.scan(/\d{1,2}:\d{2}/).first
61
63
  end
62
- date = page.search(".kategorie").text.scan(/^\d{1,2}.\d{1,2}.\d{4}/).first
63
- parse_time date, time
64
+ end
65
+
66
+ def extract_date
67
+ page.search(".kategorie").text.scan(/^\d{1,2}.\d{1,2}.\d{4}/).first
64
68
  end
65
69
 
66
70
  def parse_time date, time
@@ -96,15 +100,10 @@ module DTVTournaments
96
100
  get_first_time_until(times, index)
97
101
  end
98
102
 
99
- def self.deserialize(data)
100
- a = data.split('|')
101
- datetime = a[2]
102
-
103
+ def self.deserialize(a)
103
104
  t = Tournament.new(a[0].to_i, false)
104
105
  t.notes = a[1]
105
- t.datetime = DateTime.parse(datetime)
106
- t.time = Time.parse(datetime) - 60*60
107
- t.date = Date.parse(datetime)
106
+ t.timeFromString(a[2])
108
107
  t.street = a[3]
109
108
  t.zip = a[4]
110
109
  t.city = a[5]
@@ -112,6 +111,12 @@ module DTVTournaments
112
111
  t
113
112
  end
114
113
 
114
+ def timeFromString(datetime)
115
+ self.datetime = DateTime.parse(datetime)
116
+ self.time = Time.parse(datetime) - Time.zone_offset(Time.parse(datetime).zone)
117
+ self.date = Date.parse(datetime)
118
+ end
119
+
115
120
  def serialize
116
121
  "#{@number}|#{@notes}|#{@datetime.to_s}|#{@street}|#{@zip}|#{@city}|#{@kind}"
117
122
  end
@@ -1,3 +1,3 @@
1
1
  module DtvTournaments
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/cache_spec.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
  describe DTVTournaments::Cache do
3
- before(:all) do
3
+ before(:each) do
4
+ DTVTournaments.configure_cache do |config|
5
+ config[:active] = true
6
+ end
7
+
4
8
  @cache = DTVTournaments.get_cache
5
9
  end
6
10
  it "should return the same as given in" do
@@ -13,7 +13,12 @@ describe DTVTournaments::Tournament do
13
13
  expect(@t.datetime.to_s).to eq(DateTime.parse('20.04.2014 09:00').to_s)
14
14
  end
15
15
 
16
- it "should have the right address"
16
+ it "should have the right address" do
17
+ expect(@t.zip).to eq(13629)
18
+ expect(@t.city).to eq('Berlin')
19
+ expect(@t.street).to include('Buolstr. 14')
20
+ end
21
+
17
22
  it "should have the right kind" do
18
23
  expect(@t.kind).to eq('HGR C LAT')
19
24
  end
@@ -31,7 +36,12 @@ describe DTVTournaments::Tournament do
31
36
  expect(@t.datetime.to_s).to eq(DateTime.parse('29.03.2014 15:30').to_s)
32
37
  end
33
38
 
34
- it "should have the right address"
39
+ it "should have the right address" do
40
+ expect(@t.zip).to eq(21465)
41
+ expect(@t.city).to eq('Reinbek')
42
+ expect(@t.street).to include('Theodor-Storm-Str')
43
+ end
44
+
35
45
  it "should have the right kind" do
36
46
  expect(@t.kind).to eq('HGR D ST')
37
47
  end
@@ -83,8 +93,14 @@ describe DTVTournaments::Tournament do
83
93
  after(:each) do
84
94
  DTVTournaments.reset_cache_config
85
95
  end
96
+
97
+ it "should have a deactivated cache" do
98
+ DTVTournaments.get_cache.redis.should be_nil
99
+ end
100
+
86
101
  it "should be possible to configure a redis cache" do
87
102
  DTVTournaments.configure_cache do |config|
103
+ config[:active] = true
88
104
  config[:host] = '10.0.1.42'
89
105
  config[:port] = 6342
90
106
  config[:db] = 15
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
4
+ version: 0.1.0
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-07 00:00:00.000000000 Z
11
+ date: 2014-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubyforge_project:
140
- rubygems_version: 2.2.1
140
+ rubygems_version: 2.2.2
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: A ruby gem for fetching tournaments from the dtv tournaments portal