Class: Lego::Value::Set

Inherits:
Base
  • Object
show all
Defined in:
lib/lego/value/set.rb

Instance Method Summary collapse

Methods inherited from Base

#coerce, #parse

Constructor Details

#initialize(type, opts = {}) ⇒ Set

Returns a new instance of Set.



6
7
8
9
# File 'lib/lego/value/set.rb', line 6

def initialize(type, opts={})
  @_item_parser = Lego.value_parser(type)
  super(opts)
end

Instance Method Details

#parsersObject



11
12
13
14
15
16
17
# File 'lib/lego/value/set.rb', line 11

def parsers
  [
   ->(v) { v.respond_to?(:to_set) ? Lego.just(v.to_set) : Lego.fail("invalid set: '#{v}'") },
   ->(v) { parse_items(v) },
   ->(v) { (not allow_empty? and v.empty?) ? Lego.none : Lego.just(v) },
  ]
end