Class: Lego::Value::String

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

Instance Method Summary collapse

Methods inherited from Base

#coerce, #initialize, #parse

Constructor Details

This class inherits a constructor from Lego::Value::Base

Instance Method Details

#allow_blank?Boolean

Returns:



12
13
14
# File 'lib/lego/value/string.rb', line 12

def allow_blank?
  @opts.fetch(:allow_blank, false)
end

#parsersObject



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

#strip?Boolean

Returns:



16
17
18
# File 'lib/lego/value/string.rb', line 16

def strip?
  @opts.fetch(:strip, true)
end