Class: Yoti::MultiValue
- Inherits:
-
Object
- Object
- Yoti::MultiValue
- Defined in:
- lib/yoti/data_type/multi_value.rb
Instance Method Summary collapse
- #allow_type(type) ⇒ Object
- #filter(&callback) ⇒ Object
-
#initialize(items) ⇒ MultiValue
constructor
A new instance of MultiValue.
- #items ⇒ Object
Constructor Details
#initialize(items) ⇒ MultiValue
Returns a new instance of MultiValue.
3 4 5 6 7 8 9 |
# File 'lib/yoti/data_type/multi_value.rb', line 3 def initialize(items) raise(TypeError, "Arrays must be passed to #{self.class.name}") unless items.is_a?(Array) @original_items = items @items = items.dup @filters = [] end |
Instance Method Details
#allow_type(type) ⇒ Object
11 12 13 14 |
# File 'lib/yoti/data_type/multi_value.rb', line 11 def allow_type(type) filter { |value| value.is_a?(type) } self end |
#filter(&callback) ⇒ Object
16 17 18 19 20 |
# File 'lib/yoti/data_type/multi_value.rb', line 16 def filter(&callback) @filters.push(callback) apply_filters self end |
#items ⇒ Object
22 23 24 25 |
# File 'lib/yoti/data_type/multi_value.rb', line 22 def items apply_filters @items.clone.freeze end |