Module: DTVTournaments

Defined in:
lib/dtv_tournaments/utilities.rb,
lib/dtv_tournaments.rb,
lib/dtv_tournaments/cache.rb,
lib/dtv_tournaments/tournament.rb

Overview

Constants and helper

Defined Under Namespace

Classes: Cache, Tournament

Constant Summary collapse

FETCHINGURL =
"http://appsrv.tanzsport.de/td/db/turnier/einzel/suche"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache=(value) ⇒ Object (writeonly)

Sets the attribute cache

Parameters:

  • value

    the value to set the attribute cache to.



5
6
7
# File 'lib/dtv_tournaments/cache.rb', line 5

def cache=(value)
  @cache = value
end

.cache_configurationObject



8
9
10
11
# File 'lib/dtv_tournaments/cache.rb', line 8

def self.cache_configuration
  reset_cache_config if @cache_configuration.nil?
  @cache_configuration
end

Class Method Details

.configure_cache {|cache_configuration| ... } ⇒ Object



17
18
19
# File 'lib/dtv_tournaments/cache.rb', line 17

def self.configure_cache
  yield(cache_configuration)
end

.convertToText(content) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/dtv_tournaments/utilities.rb', line 5

def self.convertToText content
  if content.class == String
    content
  else
    content.text
  end
end

.get(number, rerun = false) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/dtv_tournaments.rb', line 9

def self.get number, rerun=false
  if rerun
    DTVTournaments::Tournament.new(number)
  else
    DTVTournaments.get_cached_tournament(number)
  end
end

.get_cacheObject



21
22
23
# File 'lib/dtv_tournaments/cache.rb', line 21

def self.get_cache
  @cache ||= Cache.new
end

.get_cached_tournament(number) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/dtv_tournaments.rb', line 17

def self.get_cached_tournament(number)
  cached = DTVTournaments.get_cache.get_by_number(number)
  if cached.nil?
    DTVTournaments.get(number, true)
  else
    cached
  end
end

.get_subelement_if_available(element, selector) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/dtv_tournaments/utilities.rb', line 13

def self.get_subelement_if_available(element, selector)
  unless element.search(selector).first.nil?
    element.search(selector).first.text
  else
    nil
  end
end

.reset_cache_configObject



13
14
15
# File 'lib/dtv_tournaments/cache.rb', line 13

def self.reset_cache_config
  @cache_configuration = {:host => '127.0.0.1', :port => 6379, :db => 1, :active => false}
end