Class: MTG::Card::Rarity
- Inherits:
-
Object
- Object
- MTG::Card::Rarity
- Includes:
- Comparable
- Defined in:
- lib/mtg/card/rarity.rb
Constant Summary collapse
- NAMES =
%w(common uncommon rare mythic\ rare)
Instance Method Summary collapse
- #<=>(rarity) ⇒ Object
- #eql?(rarity) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name) ⇒ Rarity
constructor
A new instance of Rarity.
- #to_s(format = nil) ⇒ Object
Constructor Details
Instance Method Details
#<=>(rarity) ⇒ Object
25 26 27 |
# File 'lib/mtg/card/rarity.rb', line 25 def <=>(rarity) NAMES.index(to_s) <=> NAMES.index(rarity.to_s) end |
#eql?(rarity) ⇒ Boolean
29 30 31 |
# File 'lib/mtg/card/rarity.rb', line 29 def eql?(rarity) self.class == rarity.class && self == rarity end |
#hash ⇒ Object
33 34 35 |
# File 'lib/mtg/card/rarity.rb', line 33 def hash @name.hash end |
#to_s(format = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/mtg/card/rarity.rb', line 17 def to_s(format = nil) if format == :short {'common' => 'C', 'uncommon' => 'U', 'rare' => 'R', 'mythic rare' => 'MR'}[@name] else @name end end |