Class: Basicons::Basicon

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

Constant Summary collapse

DEFAULT_HEIGHT =
16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Basicon.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/basicons/basicon.rb', line 6

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['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.



4
5
6
# File 'lib/basicons/basicon.rb', line 4

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/basicons/basicon.rb', line 4

def options
  @options
end

#symbolObject (readonly)

Returns the value of attribute symbol.



4
5
6
# File 'lib/basicons/basicon.rb', line 4

def symbol
  @symbol
end

Instance Method Details

#to_svgObject



29
30
31
# File 'lib/basicons/basicon.rb', line 29

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