Class: EacCli::Speaker::List
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #build_value(value) ⇒ Object
-
#initialize(values) ⇒ List
constructor
A new instance of List.
- #to_key(value) ⇒ Object
- #to_label(value) ⇒ Object
- #valid_labels ⇒ Object
- #valid_value?(value) ⇒ Boolean
Constructor Details
#initialize(values) ⇒ List
Returns a new instance of List.
30 31 32 33 34 |
# File 'lib/eac_cli/speaker/list.rb', line 30 def initialize(values) @values = values.map do |v| ::OpenStruct.new(key: to_key(v.key), label: to_label(v.label), value: v.value) end end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
28 29 30 |
# File 'lib/eac_cli/speaker/list.rb', line 28 def values @values end |
Class Method Details
Instance Method Details
#build_value(value) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/eac_cli/speaker/list.rb', line 52 def build_value(value) key = to_key(value) values.each do |v| # rubocop:disable Style/HashEachMethods return v.value if v.key == key end raise "Value not found: \"#{value}\" (#{values})" end |
#to_key(value) ⇒ Object
44 45 46 |
# File 'lib/eac_cli/speaker/list.rb', line 44 def to_key(value) to_label(value).downcase end |
#to_label(value) ⇒ Object
48 49 50 |
# File 'lib/eac_cli/speaker/list.rb', line 48 def to_label(value) value.to_s.strip end |
#valid_labels ⇒ Object
36 37 38 |
# File 'lib/eac_cli/speaker/list.rb', line 36 def valid_labels values.map(&:label) end |
#valid_value?(value) ⇒ Boolean
40 41 42 |
# File 'lib/eac_cli/speaker/list.rb', line 40 def valid_value?(value) values.any? { |v| v.key == to_key(value) } end |