Class: IntermatScrape::WeightClass

Inherits:
Object
  • Object
show all
Defined in:
lib/intermat_scrape/weight_class.rb

Constant Summary collapse

WEIGHT_CLASSES =
%w[125 133 141 149 157 165 174 184 197 Hwt].freeze
@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weight) ⇒ WeightClass

Returns a new instance of WeightClass.



8
9
10
11
12
# File 'lib/intermat_scrape/weight_class.rb', line 8

def initialize(weight)
  @weight = weight
  @wrestlers = []
  @@all << self
end

Instance Attribute Details

#weightObject

Returns the value of attribute weight.



2
3
4
# File 'lib/intermat_scrape/weight_class.rb', line 2

def weight
  @weight
end

#wrestlersObject

Returns the value of attribute wrestlers.



2
3
4
# File 'lib/intermat_scrape/weight_class.rb', line 2

def wrestlers
  @wrestlers
end

Class Method Details

.allObject



46
47
48
# File 'lib/intermat_scrape/weight_class.rb', line 46

def self.all
  @@all
end

.create_weight_classesObject



14
15
16
17
18
19
# File 'lib/intermat_scrape/weight_class.rb', line 14

def self.create_weight_classes
  WEIGHT_CLASSES.each do |weight|
    new(weight)
  end
  @@all
end

.find_by_weight(weight) ⇒ Object



25
26
27
# File 'lib/intermat_scrape/weight_class.rb', line 25

def self.find_by_weight(weight)
  @@all.detect { |w| w.weight == weight }
end


21
22
23
# File 'lib/intermat_scrape/weight_class.rb', line 21

def self.print_weights
  puts WEIGHT_CLASSES
end

Instance Method Details

#add_wrestler(wrestler) ⇒ Object



29
30
31
32
# File 'lib/intermat_scrape/weight_class.rb', line 29

def add_wrestler(wrestler)
  @wrestlers << wrestler
  wrestler.weight_class = self
end

#get_wrestler_by_rank(rank) ⇒ Object

TODO: move to Wrestler class?



42
43
44
# File 'lib/intermat_scrape/weight_class.rb', line 42

def get_wrestler_by_rank(rank)
  @wrestlers.detect { |w| w.rank == rank }
end

TODO: move to Wrestler class?



35
36
37
38
39
# File 'lib/intermat_scrape/weight_class.rb', line 35

def print_wrestlers
  puts ""
  puts "Rankings: ".colorize(:light_cyan)
  @wrestlers.each.with_index { |w, _i| puts "#{w.rank}\t#{w.name}" }
end