Class: Compel::Builder::String
- Includes:
- CommonValue
- Defined in:
- lib/compel/builder/string.rb
Constant Summary collapse
- URL_REGEX =
Taken from ruby_regex gem by @eparreno github.com/eparreno/ruby_regex
/(\A\z)|(\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\z)/ix
- EMAIL_REGEX =
Taken from Michael Hartl’s ‘The Ruby on Rails Tutorial’ www.railstutorial.org/book
/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
Instance Attribute Summary
Attributes inherited from Schema
Instance Method Summary collapse
- #email(options = {}) ⇒ Object
- #format(regex, options = {}) ⇒ Object
-
#initialize ⇒ String
constructor
A new instance of String.
- #url(options = {}) ⇒ Object
Methods included from CommonValue
#coerce_value!, #coerce_values_ary!, #in, #max, #min, #raise_array_error, #raise_array_values_error, #raise_value_error, #range
Methods inherited from Schema
#build_option, #default_options, #default_value, human_name, #required?, #validate
Methods included from Common
#coerce_if_proc, #default, #if, #is, #length, #max_length, #min_length, #required
Constructor Details
Instance Method Details
#email(options = {}) ⇒ Object
28 29 30 |
# File 'lib/compel/builder/string.rb', line 28 def email( = {}) build_option :format, EMAIL_REGEX, end |
#format(regex, options = {}) ⇒ Object
20 21 22 |
# File 'lib/compel/builder/string.rb', line 20 def format(regex, = {}) build_option :format, Coercion.coerce!(regex, Coercion::Regexp), end |
#url(options = {}) ⇒ Object
24 25 26 |
# File 'lib/compel/builder/string.rb', line 24 def url( = {}) build_option :format, URL_REGEX, end |