Class: UserPreferences::PreferenceDefinition
- Inherits:
-
Object
- Object
- UserPreferences::PreferenceDefinition
- Defined in:
- lib/user_preferences/preference_definition.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #binary? ⇒ Boolean
- #default ⇒ Object
-
#initialize(definition, category, name) ⇒ PreferenceDefinition
constructor
A new instance of PreferenceDefinition.
- #lookup(index) ⇒ Object
- #permitted_values ⇒ Object
- #to_db(value) ⇒ Object
Constructor Details
#initialize(definition, category, name) ⇒ PreferenceDefinition
Returns a new instance of PreferenceDefinition.
5 6 7 8 9 |
# File 'lib/user_preferences/preference_definition.rb', line 5 def initialize(definition, category, name) @definition = definition @category = category @name = name end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
3 4 5 |
# File 'lib/user_preferences/preference_definition.rb', line 3 def category @category end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/user_preferences/preference_definition.rb', line 3 def name @name end |
Instance Method Details
#binary? ⇒ Boolean
19 20 21 |
# File 'lib/user_preferences/preference_definition.rb', line 19 def binary? !@definition.is_a?(Hash) end |
#default ⇒ Object
23 24 25 |
# File 'lib/user_preferences/preference_definition.rb', line 23 def default binary? ? @definition : @definition[:default] end |
#lookup(index) ⇒ Object
27 28 29 |
# File 'lib/user_preferences/preference_definition.rb', line 27 def lookup(index) permitted_values[index] if index end |
#permitted_values ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/user_preferences/preference_definition.rb', line 11 def permitted_values if binary? result = [false, true] else @definition[:values] end end |
#to_db(value) ⇒ Object
31 32 33 34 |
# File 'lib/user_preferences/preference_definition.rb', line 31 def to_db(value) value = to_bool(value) if binary? permitted_values.index(value) end |