Class: Vario::Condition
- Inherits:
-
Object
- Object
- Vario::Condition
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/vario/condition.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #collection ⇒ Object
- #human_value ⇒ Object
-
#initialize(setting, key, value) ⇒ Condition
constructor
A new instance of Condition.
- #key_data ⇒ Object
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
#key ⇒ Object
Returns the value of attribute key.
6 7 8 |
# File 'app/models/vario/condition.rb', line 6 def key @key end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'app/models/vario/condition.rb', line 6 def value @value end |
Instance Method Details
#collection ⇒ Object
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_value ⇒ Object
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 |