Class: T::StringFormattedType

Inherits:
Object
  • Object
show all
Defined in:
lib/emery/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regex) ⇒ StringFormattedType

Returns a new instance of StringFormattedType.



103
104
105
# File 'lib/emery/type.rb', line 103

def initialize(regex)
  @regex = regex
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



102
103
104
# File 'lib/emery/type.rb', line 102

def regex
  @regex
end

Instance Method Details

#check(value) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/emery/type.rb', line 109

def check(value)
  T.check_not_nil(self, value)
  if !value.is_a? String
    raise TypeError.new("Value '#{value.inspect.to_s}' type is #{value.class} - String is required for StringFormatted")
  end
  if !@regex.match?(value)
    raise TypeError.new("Value '#{value.inspect.to_s}' is not in required format '#{@regex}'")
  end
end

#to_sObject



106
107
108
# File 'lib/emery/type.rb', line 106

def to_s
  "StringFormatted<#@regex>"
end