Class: T::StringFormattedType
- Inherits:
-
Object
- Object
- T::StringFormattedType
- Defined in:
- lib/emery/type.rb
Instance Attribute Summary collapse
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Instance Method Summary collapse
- #check(value) ⇒ Object
-
#initialize(regex) ⇒ StringFormattedType
constructor
A new instance of StringFormattedType.
- #to_s ⇒ Object
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
#regex ⇒ Object (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_s ⇒ Object
106 107 108 |
# File 'lib/emery/type.rb', line 106 def to_s "StringFormatted<#@regex>" end |