Class: Livelist::Rails::FilterCriterion

Inherits:
Object
  • Object
show all
Defined in:
lib/livelist/rails/filter_criterion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FilterCriterion

Returns a new instance of FilterCriterion.



14
15
16
17
18
19
20
21
22
# File 'lib/livelist/rails/filter_criterion.rb', line 14

def initialize(options = {})
  @filter    = options[:filter]
  @criteria  = options[:criteria]
  @reference = options[:reference]
  @type      = infer_type
  @label     = @filter.criterion_label || infer_label
  @slug      = infer_slug
  @name      = infer_name
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



7
8
9
# File 'lib/livelist/rails/filter_criterion.rb', line 7

def count
  @count
end

#labelObject

Returns the value of attribute label.



7
8
9
# File 'lib/livelist/rails/filter_criterion.rb', line 7

def label
  @label
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/livelist/rails/filter_criterion.rb', line 7

def name
  @name
end

#slugObject

Returns the value of attribute slug.



7
8
9
# File 'lib/livelist/rails/filter_criterion.rb', line 7

def slug
  @slug
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/livelist/rails/filter_criterion.rb', line 7

def type
  @type
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/livelist/rails/filter_criterion.rb', line 7

def value
  @value
end

Instance Method Details

#as_json(params) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/livelist/rails/filter_criterion.rb', line 28

def as_json(params)
  .merge(
    :slug     => @filter.slug,
    :name     => @name,
    :value    => @slug.to_s,
    :count    => @count,
    :selected => selected?(params)
  )
end

#selected?(params) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/livelist/rails/filter_criterion.rb', line 24

def selected?(params)
  params.nil? ? false : params.include?(slug.to_s)
end