Class: Taro::Types::Scalar::StringType

Inherits:
Taro::Types::ScalarType show all
Defined in:
lib/taro/types/scalar/string_type.rb

Direct Known Subclasses

UUIDv4Type

Constant Summary

Constants included from Taro::Types::Shared::Pattern

Taro::Types::Shared::Pattern::ADVANCED_RUBY_REGEXP_SYNTAX_REGEXP, Taro::Types::Shared::Pattern::NOT_ESCAPED

Instance Method Summary collapse

Methods included from Taro::Types::Shared::Pattern

included, #pattern, to_es262, validate, validate_no_advanced_syntax, validate_no_flags, validate_not_empty

Instance Method Details

#coerce_inputObject



4
5
6
7
8
9
10
11
# File 'lib/taro/types/scalar/string_type.rb', line 4

def coerce_input
  object.instance_of?(String) || input_error('must be a String')

  pattern.nil? || pattern.match?(object) ||
    input_error("must match pattern #{pattern.inspect}")

  object
end

#coerce_responseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/taro/types/scalar/string_type.rb', line 13

def coerce_response
  str =
    case object
    when String then object
    when Symbol then object.to_s
    else response_error('must be a String or Symbol')
    end

  pattern.nil? || pattern.match?(str) ||
    response_error("must match pattern #{pattern.inspect}")

  str
end