Class: Move
- Inherits:
-
Object
- Object
- Move
- Defined in:
- lib/move.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pretty_name ⇒ Object
readonly
Returns the value of attribute pretty_name.
Class Method Summary collapse
- .all ⇒ Object
- .find_or_create_by_name(name) ⇒ Object
- .find_or_create_by_pretty_name(pretty_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(name) ⇒ Move
constructor
A new instance of Move.
- #type ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/move.rb', line 5 def name @name end |
#pretty_name ⇒ Object (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
.all ⇒ Object
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
#type ⇒ Object
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 |