Class: Veneer::Conditional

Inherits:
Object
  • Object
show all
Defined in:
lib/veneer/base/conditional.rb

Defined Under Namespace

Classes: Condition, Order

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Conditional

Returns a new instance of Conditional.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/veneer/base/conditional.rb', line 9

def initialize(opts)
  @options = Hashie::Mash.new(opts || {})
  odr = [@options.delete("order")].flatten.compact
  @ordering = odr.nil? || odr.empty? ? [] : begin
    odr.map do |order|
      field, direction = order.split(" ")
      Order.new(field, (direction || :desc))
    end
  end

  conds = opts.fetch(:conditions, {})
  @conditions = conds.map do |k,v|
    field, operator = k.to_s.split(" ")
    args = [field, v]
    args << operator.to_sym if operator
    Veneer::Conditional::Condition.new(*args)
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/veneer/base/conditional.rb', line 8

def options
  @options
end

Class Method Details

.from_hash(hash) ⇒ Object



4
5
6
# File 'lib/veneer/base/conditional.rb', line 4

def self.from_hash(hash)
  new(hash)
end

Instance Method Details

#conditionsObject



40
41
42
# File 'lib/veneer/base/conditional.rb', line 40

def conditions
  @conditions
end

#limitObject



28
29
30
# File 'lib/veneer/base/conditional.rb', line 28

def limit
  @options[:limit]
end

#offsetObject



32
33
34
# File 'lib/veneer/base/conditional.rb', line 32

def offset
  @options[:offset]
end

#orderObject



36
37
38
# File 'lib/veneer/base/conditional.rb', line 36

def order
  @ordering
end