class UiBibz::Ui::Core::Icons::Star

Create star notation

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

Signatures

UiBibz::Ui::Core::Icons::Star.new(content, options = nil, html_options = nil)

UiBibz::Ui::Core::Icons::Star.new(options = nil, html_options = nil) do
  content
end

Examples

UiBibz::Ui::Core::Icons::Star.new(content, status: :success).render

UiBibz::Ui::Core::Icons::Star.new({ num: 10 }) do
  #content
end.render

Helper

star(content, options = {}, html_options = {})

star(options = {}, html_options = {}) do
  content
end

Public Instance Methods

pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/icons/star.rb, line 50
def pre_render
  content_tag :span, star_notation.join(' ').html_safe, html_options
end

Private Instance Methods

component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/icons/star.rb, line 56
def component_html_classes
  'stars-notation'
end
glyph_opts() click to toggle source
# File lib/ui_bibz/ui/core/icons/star.rb, line 74
def glyph_opts
  opts = {}
  opts = opts.merge({ status: options[:status] }) unless options[:status].nil?
  opts = opts.merge({ size: options[:size] }) unless options[:size].nil?
  opts
end
number() click to toggle source
# File lib/ui_bibz/ui/core/icons/star.rb, line 60
def number
  (options[:num] || 5).to_i
end
star_name(star) click to toggle source
# File lib/ui_bibz/ui/core/icons/star.rb, line 81
def star_name(star)
  if star <= content
    { name: 'star', style: :solid }
  elsif star > content && !content.is_a?(Integer) && star < content + 1
    { name: 'star-half-alt', style: :solid }
  else
    { name: 'star', style: :regular }
  end
end
star_notation() click to toggle source
# File lib/ui_bibz/ui/core/icons/star.rb, line 64
def star_notation
  stars = []
  number.times do |star|
    star += 1
    star_options = star_name(star).merge(glyph_opts)
    stars << UiBibz::Ui::Core::Icons::Glyph.new(star_options).render
  end
  stars
end