Class: Emery::T::StringFormatted

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regex) ⇒ StringFormatted

Returns a new instance of StringFormatted.



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

def initialize(regex)
  @regex = regex
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



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

def regex
  @regex
end

Instance Method Details

#check(value) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/emery/type.rb', line 112

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



109
110
111
# File 'lib/emery/type.rb', line 109

def to_s
  "String<#@regex>"
end