Class: MtgCardMaker::IconService
- Inherits:
-
Object
- Object
- MtgCardMaker::IconService
- Defined in:
- lib/mtg_card_maker/icon_service.rb
Overview
IconService loads and renders SVG icons for mana costs. This service handles loading, caching, and resizing of SVG icons for different mana colors and special symbols.
Constant Summary collapse
- ICONS_DIR =
File.join(__dir__, 'icons')
- QR_CODE_PATH =
File.join(ICONS_DIR, 'qrcode.svg')
- JSHARP_PATH =
File.join(ICONS_DIR, 'jsharp.svg')
- ICON_SETS =
Available icon sets
{ default: { white: 'white.svg', blue: 'blue.svg', black: 'black.svg', red: 'red.svg', green: 'green.svg', colorless: 'colorless.svg' } }.freeze
Instance Attribute Summary collapse
- #icon_set ⇒ Object readonly
Instance Method Summary collapse
-
#available_colors ⇒ Object
Returns a list of available colors for the current icon set.
-
#available_icon_sets ⇒ Object
Returns a list of available icon sets.
-
#icon_svg(color, size: 30) ⇒ Object
Returns the SVG content for a given color and icon set.
-
#initialize(icon_set = :default) ⇒ IconService
constructor
A new instance of IconService.
-
#jsharp_svg ⇒ Object
Returns the jsharp icon SVG content.
-
#qr_code_svg ⇒ Object
Returns the QR code SVG content.
Constructor Details
#initialize(icon_set = :default) ⇒ IconService
Returns a new instance of IconService.
34 35 36 37 |
# File 'lib/mtg_card_maker/icon_service.rb', line 34 def initialize(icon_set = :default) @icon_set = icon_set @cached_icons = {} end |
Instance Attribute Details
#icon_set ⇒ Object (readonly)
32 33 34 |
# File 'lib/mtg_card_maker/icon_service.rb', line 32 def icon_set @icon_set end |
Instance Method Details
#available_colors ⇒ Object
Returns a list of available colors for the current icon set
65 66 67 |
# File 'lib/mtg_card_maker/icon_service.rb', line 65 def available_colors ICON_SETS[icon_set]&.keys || [] end |
#available_icon_sets ⇒ Object
Returns a list of available icon sets
70 71 72 |
# File 'lib/mtg_card_maker/icon_service.rb', line 70 def available_icon_sets ICON_SETS.keys end |
#icon_svg(color, size: 30) ⇒ Object
Returns the SVG content for a given color and icon set
40 41 42 43 44 45 46 47 48 |
# File 'lib/mtg_card_maker/icon_service.rb', line 40 def icon_svg(color, size: 30) return nil unless valid_color?(color) icon_path = icon_path_for_color(color) return nil unless File.exist?(icon_path) svg_content = load_icon(icon_path) resize_svg(svg_content, size) end |
#jsharp_svg ⇒ Object
Returns the jsharp icon SVG content
58 59 60 61 62 |
# File 'lib/mtg_card_maker/icon_service.rb', line 58 def jsharp_svg return nil unless File.exist?(JSHARP_PATH) load_icon(JSHARP_PATH) end |
#qr_code_svg ⇒ Object
Returns the QR code SVG content
51 52 53 54 55 |
# File 'lib/mtg_card_maker/icon_service.rb', line 51 def qr_code_svg return nil unless File.exist?(QR_CODE_PATH) load_icon(QR_CODE_PATH) end |