Class: Move

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Move

Returns a new instance of Move.



8
9
10
11
12
13
# File 'lib/move.rb', line 8

def initialize(name)
  @name = name
  @pretty_name = name.split("-").collect{|word| word.capitalize}.join(" ")
  
  @@all << self
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pretty_nameObject (readonly)

Returns the value of attribute pretty_name.



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

def pretty_name
  @pretty_name
end

Class Method Details

.allObject



22
23
24
# File 'lib/move.rb', line 22

def self.all
  @@all
end

.find_or_create_by_name(name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/move.rb', line 26

def self.find_or_create_by_name(name)
  if Scraper.moves.include?(name)
    return self.all.detect{|a| a.name == name} if self.all.collect{|a| a.name}.include?(name)
    return Move.new(name)
  end
  return nil
end

.find_or_create_by_pretty_name(pretty_name) ⇒ Object



34
35
36
# File 'lib/move.rb', line 34

def self.find_or_create_by_pretty_name(pretty_name)
  self.find_or_create_by_name(pretty_name.split(" ").collect{|word| word.downcase}.join("-"))
end

Instance Method Details

#typeObject



15
16
17
18
19
20
# File 'lib/move.rb', line 15

def type
  if @type == nil
    @type = Scraper.get_move_by_name(name)["type"]["name"]
  end
  @type
end