Class: Emery::T::StringFormatted
- Inherits:
-
Object
- Object
- Emery::T::StringFormatted
- 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) ⇒ StringFormatted
constructor
A new instance of StringFormatted.
- #to_s ⇒ Object
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
#regex ⇒ Object (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_s ⇒ Object
109 110 111 |
# File 'lib/emery/type.rb', line 109 def to_s "String<#@regex>" end |