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
43 44 45 46 47 48 |
# File 'lib/eac_cli/speaker/list.rb', line 43 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
43 44 45 46 47 48 |
# File 'lib/eac_cli/speaker/list.rb', line 43 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
74 75 76 77 78 79 80 |
# File 'lib/eac_cli/speaker/list.rb', line 74 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
51 52 53 |
# File 'lib/eac_cli/speaker/list.rb', line 51 def ignore_case? .if_key(OPTION_IGNORE_CASE, DEFAULT_IGNORE_CASE, &:to_bool) end |
#to_key(value) ⇒ String
65 66 67 68 |
# File 'lib/eac_cli/speaker/list.rb', line 65 def to_key(value) r = to_label(value) ignore_case? ? r.downcase : r end |
#to_label(value) ⇒ Object
70 71 72 |
# File 'lib/eac_cli/speaker/list.rb', line 70 def to_label(value) value.to_s.strip end |
#valid_labels ⇒ Object
55 56 57 |
# File 'lib/eac_cli/speaker/list.rb', line 55 def valid_labels values.map(&:label) end |
#valid_value?(value) ⇒ Boolean
59 60 61 |
# File 'lib/eac_cli/speaker/list.rb', line 59 def valid_value?(value) values.any? { |v| v.key == to_key(value) } end |