Class: 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.



112
113
114
# File 'lib/emery/type.rb', line 112

def initialize(regex)
  @regex = regex
end

Instance Attribute Details

#regexObject (readonly)

Returns the value of attribute regex.



111
112
113
# File 'lib/emery/type.rb', line 111

def regex
  @regex
end

Instance Method Details

#check(value) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/emery/type.rb', line 118

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



115
116
117
# File 'lib/emery/type.rb', line 115

def to_s
  "String<#@regex>"
end