Class: PhosphorIcons::Icon

Inherits:
Object
  • Object
show all
Defined in:
lib/phosphor_icons/icon.rb

Constant Summary collapse

DEFAULT_STYLE =
"regular"
SUPPORTED_STYLES =
[DEFAULT_STYLE, "bold", "light", "duotone", "fill", "thin"]
NATURAL_HEIGHTS =
[16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80]
DEFAULT_HEIGHT =
24

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol, options = {}) ⇒ Icon

Returns a new instance of Icon.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/phosphor_icons/icon.rb', line 12

def initialize(symbol, options = {})
  @symbol = symbol.to_s
  @style = options[:style] || DEFAULT_STYLE
  if (phosphor_icon = get_phosphor_icon(@symbol, options))
    @path = phosphor_icon["path"]
    @width = phosphor_icon["width"]
    @height = phosphor_icon["height"]
    @options = {
      class: "phosphor-icon #{options[:class]}".strip,
      viewBox: viewbox,
      xmlns: "http://www.w3.org/2000/svg",
      fill: "currentColor",
      width: @width,
      height: @height,
    }
  else
    raise IconNotFoundError, "Couldn't find #{self}"
  end
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



10
11
12
# File 'lib/phosphor_icons/icon.rb', line 10

def height
  @height
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/phosphor_icons/icon.rb', line 10

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/phosphor_icons/icon.rb', line 10

def path
  @path
end

#styleObject (readonly)

Returns the value of attribute style.



10
11
12
# File 'lib/phosphor_icons/icon.rb', line 10

def style
  @style
end

#symbolObject (readonly)

Returns the value of attribute symbol.



10
11
12
# File 'lib/phosphor_icons/icon.rb', line 10

def symbol
  @symbol
end

#widthObject (readonly)

Returns the value of attribute width.



10
11
12
# File 'lib/phosphor_icons/icon.rb', line 10

def width
  @width
end

Instance Method Details

#to_sObject



36
37
38
# File 'lib/phosphor_icons/icon.rb', line 36

def to_s
  "Phosphor Icon for #{symbol.inspect} with style #{style.inspect}"
end

#to_svgObject



32
33
34
# File 'lib/phosphor_icons/icon.rb', line 32

def to_svg
  "<svg #{html_attributes}>#{path}</svg>"
end