Class: EnumX::ValueList
- Inherits:
-
Object
- Object
- EnumX::ValueList
- Includes:
- Enumerable
- Defined in:
- lib/enum_x/value_list.rb
Overview
A list of multiple enum values.
Instance Attribute Summary collapse
-
#enum ⇒ Object
readonly
Attributes.
-
#values ⇒ Object
(also: #to_ary, #to_a)
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](value) ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize(enum, values) ⇒ ValueList
constructor
Initialization.
-
#to_s ⇒ Object
Creates a string representation of the values.
Constructor Details
#initialize(enum, values) ⇒ ValueList
Initialization
9 10 11 12 13 |
# File 'lib/enum_x/value_list.rb', line 9 def initialize(enum, values) @enum = enum values = [ values ] unless values.is_a?(Enumerable) @values = values.map { |value| @enum[value] || value } end |
Instance Attribute Details
#enum ⇒ Object (readonly)
Attributes
18 19 20 |
# File 'lib/enum_x/value_list.rb', line 18 def enum @enum end |
#values ⇒ Object (readonly) Also known as: to_ary, to_a
Returns the value of attribute values.
20 21 22 |
# File 'lib/enum_x/value_list.rb', line 20 def values @values end |
Instance Method Details
#==(other) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/enum_x/value_list.rb', line 57 def ==(other) case other when Array then values == other when EnumX::ValueList then values == other.values when EnumX::Value then values == [ other ] else false end end |
#[](value) ⇒ Object
49 50 51 |
# File 'lib/enum_x/value_list.rb', line 49 def [](value) values.find { |val| val.to_s == value.to_s } end |
#include?(value) ⇒ Boolean
53 54 55 |
# File 'lib/enum_x/value_list.rb', line 53 def include?(value) values.any? { |val| val.to_s == value.to_s } end |
#to_s ⇒ Object
Creates a string representation of the values.
34 35 36 |
# File 'lib/enum_x/value_list.rb', line 34 def to_s values.map(&:to_s).join(', ') end |