Class: Vario::Condition

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/vario/condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting, key, value) ⇒ Condition

Returns a new instance of Condition.



8
9
10
11
12
# File 'app/models/vario/condition.rb', line 8

def initialize(setting, key, value)
  @setting = setting
  @key = key
  @value = value
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



6
7
8
# File 'app/models/vario/condition.rb', line 6

def key
  @key
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'app/models/vario/condition.rb', line 6

def value
  @value
end

Instance Method Details

#collectionObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/vario/condition.rb', line 26

def collection
  return @collection if @collection

  @collection = key_data[:collection]
  @collection ||= instance_exec(&key_data[:collection_proc]) if key_data[:collection_proc]
  @collection ||= []
  if value.present?
    current_value = @collection.find { |entry| entry.last == value }
    @collection << ["<#{value}>", value] unless current_value
  end
  @collection
end

#human_valueObject



14
15
16
17
18
19
20
# File 'app/models/vario/condition.rb', line 14

def human_value
  if key_data[:type] == :select
    collection.find { |entry| entry.last == value }.first
  else
    value
  end
end

#key_dataObject



22
23
24
# File 'app/models/vario/condition.rb', line 22

def key_data
  Vario.config.key_data_for(key)
end