Class: Lego::Value::String
- Inherits:
-
Base
- Object
- Base
- Lego::Value::String
show all
- Defined in:
- lib/lego/value/string.rb
Instance Method Summary
collapse
Methods inherited from Base
#coerce, #initialize, #parse
Instance Method Details
#allow_blank? ⇒ Boolean
12
13
14
|
# File 'lib/lego/value/string.rb', line 12
def allow_blank?
@opts.fetch(:allow_blank, false)
end
|
#parsers ⇒ Object
4
5
6
7
8
9
10
|
# File 'lib/lego/value/string.rb', line 4
def parsers
[
->(v) { v.respond_to?(:to_str) ? Lego.just(v.to_str) : Lego.fail("invalid string: '#{v}'") },
->(v) { strip? ? Lego.just(v.strip) : Lego.just(v) },
->(v) { (not allow_blank? and v.blank?) ? Lego.none : Lego.just(v) },
]
end
|
16
17
18
|
# File 'lib/lego/value/string.rb', line 16
def strip?
@opts.fetch(:strip, true)
end
|