Class: Condition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ Condition

Returns a new instance of Condition.

Yields:

  • (_self)

Yield Parameters:

  • _self (Condition)

    the object that the method was called on



4
5
6
7
8
9
10
# File 'lib/condition.rb', line 4

def initialize(attributes={})
  @id = RansackQuery.generate_id
  @predicate = attributes[:predicate] || :eq
  @attribute = attributes[:attribute]
  @value = attributes[:value]
  yield self if block_given?
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute.



2
3
4
# File 'lib/condition.rb', line 2

def attribute
  @attribute
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/condition.rb', line 2

def id
  @id
end

#predicateObject

Returns the value of attribute predicate.



2
3
4
# File 'lib/condition.rb', line 2

def predicate
  @predicate
end

#valueObject

Returns the value of attribute value.



2
3
4
# File 'lib/condition.rb', line 2

def value
  @value
end

Instance Method Details

#ransackifyObject



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

def ransackify
  {
      @id => {
          'a' => build_ransack_array(@attribute, 'name'),
          'p' => @predicate.to_s,
          'v' => build_ransack_array(@value, 'value')
      }
  }
end