Class: EacCli::Speaker::List
Defined Under Namespace
Classes: VALUE_STRUCT
Constant Summary collapse
- DEFAULT_IGNORE_CASE =
true
Instance Attribute Summary collapse
-
#values ⇒ Array<VALUE_STRUCT>, Hash
readonly
# @!attribute [r] options.
Class Method Summary collapse
Instance Method Summary collapse
- #build_value(value) ⇒ Object
- #ignore_case? ⇒ Boolean
- #initialize(values) ⇒ Object constructor
- #to_key(value) ⇒ String
- #to_label(value) ⇒ Object
- #valid_labels ⇒ Object
- #valid_value?(value) ⇒ Boolean
Constructor Details
#initialize(values) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/eac_cli/speaker/list.rb', line 44 common_constructor :values, :options, default: [{}] do self. = self.class.lists.option.hash_keys_validate!() self.values = values.map do |v| VALUE_STRUCT.new(to_key(v.key), to_label(v.label), v.value) end end |
Instance Attribute Details
#values ⇒ Array<VALUE_STRUCT>, Hash (readonly)
# @!attribute [r] options
44 45 46 47 48 49 |
# File 'lib/eac_cli/speaker/list.rb', line 44 common_constructor :values, :options, default: [{}] do self. = self.class.lists.option.hash_keys_validate!() self.values = values.map do |v| VALUE_STRUCT.new(to_key(v.key), to_label(v.label), v.value) end end |
Class Method Details
Instance Method Details
#build_value(value) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/eac_cli/speaker/list.rb', line 75 def build_value(value) key = to_key(value) values.each do |v| return v.value if v.key == key end raise "Value not found: \"#{value}\" (#{values})" end |
#ignore_case? ⇒ Boolean
52 53 54 |
# File 'lib/eac_cli/speaker/list.rb', line 52 def ignore_case? .if_key(OPTION_IGNORE_CASE, DEFAULT_IGNORE_CASE, &:to_bool) end |
#to_key(value) ⇒ String
66 67 68 69 |
# File 'lib/eac_cli/speaker/list.rb', line 66 def to_key(value) r = to_label(value) ignore_case? ? r.downcase : r end |
#to_label(value) ⇒ Object
71 72 73 |
# File 'lib/eac_cli/speaker/list.rb', line 71 def to_label(value) value.to_s.strip end |
#valid_labels ⇒ Object
56 57 58 |
# File 'lib/eac_cli/speaker/list.rb', line 56 def valid_labels values.map(&:label) end |
#valid_value?(value) ⇒ Boolean
60 61 62 |
# File 'lib/eac_cli/speaker/list.rb', line 60 def valid_value?(value) values.any? { |v| v.key == to_key(value) } end |