Class: MtgCardMaker::ManaCost
- Inherits:
-
Object
- Object
- MtgCardMaker::ManaCost
- Defined in:
- lib/mtg_card_maker/mana_cost.rb
Overview
Mana cost class that generates SVG for the mana cost of a card. This class parses mana cost strings (e.g., "2UR", "XG") and generates SVG circles with appropriate colors and icons for each mana symbol.
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- COLOR_MAP =
Mapping of letters to colors
{ 'B' => :black, 'S' => :black, 'U' => :blue, 'I' => :blue, 'G' => :green, 'F' => :green, 'W' => :white, 'P' => :white, 'R' => :red, 'M' => :red, 'C' => :colorless }.freeze
Instance Attribute Summary collapse
-
#elements ⇒ Array<Symbol>
readonly
The parsed mana elements.
-
#int_val ⇒ Integer?
readonly
The integer value for generic mana.
Instance Method Summary collapse
-
#initialize(mana_string = nil, icon_set = :default) ⇒ ManaCost
constructor
Initialize a new mana cost parser.
-
#to_svg ⇒ String
Returns SVG string for the mana cost circles with drop shadow.
Constructor Details
#initialize(mana_string = nil, icon_set = :default) ⇒ ManaCost
Initialize a new mana cost parser
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mtg_card_maker/mana_cost.rb', line 42 def initialize(mana_string = nil, icon_set = :default) # rubocop:disable Metrics/MethodLength @elements = [] @origins = [] # :numeric, :C, or color symbol @int_val = nil @original_string = mana_string @icon_service = IconService.new(icon_set) return if mana_string.nil? || mana_string.empty? # Convert to uppercase for consistency mana_string = mana_string.to_s.upcase # Parse the mana string parse_mana_string(mana_string) # Limit to maximum circles layer_config = LayerConfig.default max_circles = layer_config.mana_cost_config[:max_circles] @elements = @elements.first(max_circles) @origins = @origins.first(max_circles) end |
Instance Attribute Details
#elements ⇒ Array<Symbol> (readonly)
Returns the parsed mana elements.
33 34 35 |
# File 'lib/mtg_card_maker/mana_cost.rb', line 33 def elements @elements end |
#int_val ⇒ Integer? (readonly)
Returns the integer value for generic mana.
36 37 38 |
# File 'lib/mtg_card_maker/mana_cost.rb', line 36 def int_val @int_val end |
Instance Method Details
#to_svg ⇒ String
Returns SVG string for the mana cost circles with drop shadow
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/mtg_card_maker/mana_cost.rb', line 67 def to_svg layer_config = LayerConfig.default circle_spacing = layer_config.mana_cost_config[:circle_spacing] # Build mana cost circles SVG mana_circles = @elements.each_with_index.map do |color, i| x = i * circle_spacing y = 0 mana_element_svg(x, y, color, @origins[i]) end.join " \#{drop_shadow_filter}\n <g filter=\"url(#mana-cost-drop-shadow)\">\n \#{mana_circles}\n </g>\n SVG\nend\n".delete("\n") |