Class: MaimaiNet::UserOption::Option
- Inherits:
-
Struct
- Object
- Struct
- MaimaiNet::UserOption::Option
- Defined in:
- lib/maimai_net/user_option.rb
Instance Attribute Summary collapse
-
#choices ⇒ Object
Returns the value of attribute choices.
-
#name ⇒ Object
Returns the value of attribute name.
-
#selected ⇒ Object
Returns the value of attribute selected.
Instance Method Summary collapse
- #select(value) ⇒ Object (also: #pick)
- #selected_id ⇒ Object
- #to_a ⇒ Object (also: #to_ary)
- #to_h ⇒ Object (also: #to_hash)
Instance Attribute Details
#choices ⇒ Object
Returns the value of attribute choices
3 4 5 |
# File 'lib/maimai_net/user_option.rb', line 3 def choices @choices end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/maimai_net/user_option.rb', line 3 def name @name end |
#selected ⇒ Object
Returns the value of attribute selected
3 4 5 |
# File 'lib/maimai_net/user_option.rb', line 3 def selected @selected end |
Instance Method Details
#select(value) ⇒ Object Also known as: pick
4 5 6 7 8 9 10 11 |
# File 'lib/maimai_net/user_option.rb', line 4 def select(value) new_selected = choices.find do |choice| choice.match?(value) end fail ArgumentError, "invalid value selected" if new_selected.nil? self.selected = new_selected end |
#selected_id ⇒ Object
15 16 17 |
# File 'lib/maimai_net/user_option.rb', line 15 def selected_id self.selected.value end |
#to_a ⇒ Object Also known as: to_ary
19 20 21 |
# File 'lib/maimai_net/user_option.rb', line 19 def to_a [self.name, self.selected_id] end |
#to_h ⇒ Object Also known as: to_hash
23 24 25 |
# File 'lib/maimai_net/user_option.rb', line 23 def to_h Hash[*to_a] end |