Class: Sirens::ChoiceModel
- Inherits:
-
Object
- Object
- Sirens::ChoiceModel
- Defined in:
- lib/models/choice_model.rb
Instance Method Summary collapse
- #choices ⇒ Object
-
#has_selection ⇒ Object
Asking.
-
#initialize(selection: nil, choices: []) ⇒ ChoiceModel
constructor
Initializing.
- #item_at(index:) ⇒ Object
-
#selection ⇒ Object
Accessing.
- #set_choices(list) ⇒ Object
- #set_selection(new_value) ⇒ Object
Constructor Details
#initialize(selection: nil, choices: []) ⇒ ChoiceModel
Initializing
6 7 8 9 10 11 |
# File 'lib/models/choice_model.rb', line 6 def initialize(selection: nil, choices: []) super() @selection = ValueModel.on(selection) @choices = ListModel.on(choices) end |
Instance Method Details
#choices ⇒ Object
23 24 25 |
# File 'lib/models/choice_model.rb', line 23 def choices() @choices end |
#has_selection ⇒ Object
Asking
37 38 39 |
# File 'lib/models/choice_model.rb', line 37 def has_selection() ! @selection.value.nil? end |
#item_at(index:) ⇒ Object
31 32 33 |
# File 'lib/models/choice_model.rb', line 31 def item_at(index:) @choices[index] end |
#selection ⇒ Object
Accessing
15 16 17 |
# File 'lib/models/choice_model.rb', line 15 def selection() @selection end |
#set_choices(list) ⇒ Object
27 28 29 |
# File 'lib/models/choice_model.rb', line 27 def set_choices(list) @choices.set_list(list) end |
#set_selection(new_value) ⇒ Object
19 20 21 |
# File 'lib/models/choice_model.rb', line 19 def set_selection(new_value) @selection.set_value(new_value) end |