Class: MaimaiNet::UserOption::Option

Inherits:
Struct
  • Object
show all
Defined in:
lib/maimai_net/user_option.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#choicesObject

Returns the value of attribute choices

Returns:

  • (Object)

    the current value of choices



3
4
5
# File 'lib/maimai_net/user_option.rb', line 3

def choices
  @choices
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/maimai_net/user_option.rb', line 3

def name
  @name
end

#selectedObject

Returns the value of attribute selected

Returns:

  • (Object)

    the current value of 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_idObject



15
16
17
# File 'lib/maimai_net/user_option.rb', line 15

def selected_id
  self.selected.value
end

#to_aObject 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_hObject Also known as: to_hash



23
24
25
# File 'lib/maimai_net/user_option.rb', line 23

def to_h
  Hash[*to_a]
end