Class: PlayerSetHistory::Tournament

Inherits:
Object
  • Object
show all
Defined in:
lib/player_set_history/tournament.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, date) ⇒ Tournament

Returns a new instance of Tournament.



7
8
9
10
11
12
# File 'lib/player_set_history/tournament.rb', line 7

def initialize (name, date)
  @name = name
  @date = DateTime.strptime(date.to_s,'%s').to_s[0..9]
  @@all << self
  @sets = []
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/player_set_history/tournament.rb', line 4

def date
  @date
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/player_set_history/tournament.rb', line 4

def name
  @name
end

#setsObject

Returns the value of attribute sets.



4
5
6
# File 'lib/player_set_history/tournament.rb', line 4

def sets
  @sets
end

#winnerObject

Returns the value of attribute winner.



4
5
6
# File 'lib/player_set_history/tournament.rb', line 4

def winner
  @winner
end

Class Method Details

.allObject



14
15
16
# File 'lib/player_set_history/tournament.rb', line 14

def self.all 
  @@all
end

.find_or_create_from_name(name, date) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/player_set_history/tournament.rb', line 22

def self.find_or_create_from_name (name, date)
   tourny_index = self.all.index {|x| x.name == name}
   
   if tourny_index == nil
     tourny = PlayerSetHistory::Tournament.new(name, date)
   else
     tourny = self.all[tourny_index]
   end
   
   return tourny
end

Instance Method Details

#add_set(set) ⇒ Object



18
19
20
# File 'lib/player_set_history/tournament.rb', line 18

def add_set(set)
  @sets << set
end