Class: MtgCardMaker::IconService

Inherits:
Object
  • Object
show all
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.

Examples:

service = MtgCardMaker::IconService.new
svg = service.icon_svg(:red, size: 24)

Since:

  • 0.1.0

Constant Summary collapse

ICONS_DIR =

Since:

  • 0.1.0

File.join(__dir__, 'icons')
QR_CODE_PATH =

Since:

  • 0.1.0

File.join(ICONS_DIR, 'qrcode.svg')
JSHARP_PATH =

Since:

  • 0.1.0

File.join(ICONS_DIR, 'jsharp.svg')
ICON_SETS =

Available icon sets

Since:

  • 0.1.0

{
  default: {
    white: 'white.svg',
    blue: 'blue.svg',
    black: 'black.svg',
    red: 'red.svg',
    green: 'green.svg',
    colorless: 'colorless.svg'
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(icon_set = :default) ⇒ IconService

Returns a new instance of IconService.

Since:

  • 0.1.0



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_setObject (readonly)

Since:

  • 0.1.0



32
33
34
# File 'lib/mtg_card_maker/icon_service.rb', line 32

def icon_set
  @icon_set
end

Instance Method Details

#available_colorsObject

Returns a list of available colors for the current icon set

Since:

  • 0.1.0



65
66
67
# File 'lib/mtg_card_maker/icon_service.rb', line 65

def available_colors
  ICON_SETS[icon_set]&.keys || []
end

#available_icon_setsObject

Returns a list of available icon sets

Since:

  • 0.1.0



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

Since:

  • 0.1.0



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_svgObject

Returns the jsharp icon SVG content

Since:

  • 0.1.0



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_svgObject

Returns the QR code SVG content

Since:

  • 0.1.0



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