class MaterialIcons::Rails::MaterialIcon

Public Class Methods

new(icon, options = {}) click to toggle source
Calls superclass method
# File lib/material_icons/rails/material_icon.rb, line 9
def initialize(icon, options = {})
  super(options.merge({icon: icon.to_sym}))
  fill_defaults
  normalize
end

Public Instance Methods

style() click to toggle source
# File lib/material_icons/rails/material_icon.rb, line 19
def style
  {
    'font-size': size,
  }.collect{ |k, v| "#{k}: #{v}"}.join('; ')
end
to_html() click to toggle source
# File lib/material_icons/rails/material_icon.rb, line 15
def to_html
  content_tag(self[:tag], self[:icon], style_options_attributes.collect{ |a| [a, self[a] || self.send(a)] }.to_h) + self[:text]
end

Private Instance Methods

fill_defaults() click to toggle source
# File lib/material_icons/rails/material_icon.rb, line 27
def fill_defaults
  {
    tag: 'i',
    text: '',
    size: '1em',
  }.each{ |k, v| self[k] = v unless self[k].present? }
end
normalize() click to toggle source
# File lib/material_icons/rails/material_icon.rb, line 35
def normalize
  self[:size] = case self[:size]
  when /^\d+x$/ then "#{size.to_i}em"
  when self[:size].to_i.to_s then "#{size}px"
  else self[:size]
  end

  self[:class] = case self[:class]
  when Array then self[:class]
  when String then self[:class].split(' ')
  else []
  end.concat(['material-icons'])
end