Class: MTG::Card::ManaCost
- Inherits:
-
Object
- Object
- MTG::Card::ManaCost
- Defined in:
- lib/mtg/card/mana_cost.rb
Constant Summary collapse
- NON_ZERO_PATTERN =
/^(X*)([1-9]\d*)?([BGRUW]*)$/
Instance Method Summary collapse
- #converted ⇒ Object
-
#initialize(str) ⇒ ManaCost
constructor
A new instance of ManaCost.
- #to_s ⇒ Object
Constructor Details
#initialize(str) ⇒ ManaCost
Returns a new instance of ManaCost.
7 8 9 10 11 12 13 |
# File 'lib/mtg/card/mana_cost.rb', line 7 def initialize(str) str = str.to_s.strip.upcase if (str != '') && str != '0' && !(str =~ NON_ZERO_PATTERN) raise ArgumentError, "invalid mana cost" end @str = str end |
Instance Method Details
#converted ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/mtg/card/mana_cost.rb', line 19 def converted if ['', '0'].include?(@str) 0 else @str =~ NON_ZERO_PATTERN $2.to_i + $3.length end end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/mtg/card/mana_cost.rb', line 15 def to_s @str end |