Class: Basicons::Basicon

Inherits:
Object
  • Object
show all
Defined in:
lib/basicons/basicon.rb

Constant Summary collapse

SVG_SIZES =
{
  small: 16,
  medium: 32,
  large: 64
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Basicon.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/basicons/basicon.rb', line 12

def initialize(symbol, options = {})
  @symbol = symbol.to_s
  @options = options.dup

  if @data = Basicons::SVG_DATA[@symbol]
    @options.merge!({
      class: classes,
      width: svg_size,
      height: svg_size,
      viewBox: '0 0 24 24',
      stroke: 'currentColor',
      fill: 'none'
    })

    @options.delete(:size)
    @options['stroke-width'] = 2
    @options['stroke-linecap'] = 'round'
    @options['stroke-linejoin'] = 'round'
    @options['xmlns'] = 'http://www.w3.org/2000/svg'
  else
    raise "<#{@symbol}> not found"
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/basicons/basicon.rb', line 9

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/basicons/basicon.rb', line 10

def options
  @options
end

#sizeObject (readonly)

Returns the value of attribute size.



9
10
11
# File 'lib/basicons/basicon.rb', line 9

def size
  @size
end

#symbolObject (readonly)

Returns the value of attribute symbol.



10
11
12
# File 'lib/basicons/basicon.rb', line 10

def symbol
  @symbol
end

Instance Method Details

#to_svgObject



36
37
38
# File 'lib/basicons/basicon.rb', line 36

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