Class: Sirens::ChoiceModel

Inherits:
Object
  • Object
show all
Defined in:
lib/models/choice_model.rb

Instance Method Summary collapse

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

#choicesObject



23
24
25
# File 'lib/models/choice_model.rb', line 23

def choices()
    @choices
end

#has_selectionObject

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

#selectionObject

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