Class: AjaxfulRating::StarsBuilder

Inherits:
Object
  • Object
show all
Includes:
Locale
Defined in:
lib/axr/stars_builder.rb

Overview

:nodoc: :nodoc:

Constant Summary

Constant Summary

Constants included from Locale

Locale::DEFAULTS

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Locale

#i18n

Constructor Details

- (StarsBuilder) initialize(rateable, user_or_static, template, css_builder, options = {})



7
8
9
10
11
# File 'lib/axr/stars_builder.rb', line 7

def initialize(rateable, user_or_static, template, css_builder, options = {})
  @user = user_or_static unless user_or_static == :static
  @rateable, @template, @css_builder = rateable, template, css_builder
  apply_stars_builder_options!(options)
end

Instance Attribute Details

- (Object) options (readonly)

Returns the value of attribute options



5
6
7
# File 'lib/axr/stars_builder.rb', line 5

def options
  @options
end

- (Object) rateable (readonly)

Returns the value of attribute rateable



5
6
7
# File 'lib/axr/stars_builder.rb', line 5

def rateable
  @rateable
end

- (Object) user (readonly)

Returns the value of attribute user



5
6
7
# File 'lib/axr/stars_builder.rb', line 5

def user
  @user
end

Instance Method Details

- (Object) render



22
23
24
# File 'lib/axr/stars_builder.rb', line 22

def render
  options[:wrap] ? wrapper_tag : ratings_tag
end

- (Object) show_value



13
14
15
16
17
18
19
20
# File 'lib/axr/stars_builder.rb', line 13

def show_value
  if options[:show_user_rating]
    rate = rateable.rate_by(user, options[:dimension]) if user
    rate ? rate.stars : 0
  else
    rateable.rate_average(true, options[:dimension])
  end
end