Class: Compel::Builder::String

Inherits:
Schema
  • Object
show all
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

#options, #type

Instance Method Summary collapse

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

#initializeString

Returns a new instance of String.



16
17
18
# File 'lib/compel/builder/string.rb', line 16

def initialize
  super(Coercion::String)
end

Instance Method Details

#email(options = {}) ⇒ Object



28
29
30
# File 'lib/compel/builder/string.rb', line 28

def email(options = {})
  build_option :format, EMAIL_REGEX, options
end

#format(regex, options = {}) ⇒ Object



20
21
22
# File 'lib/compel/builder/string.rb', line 20

def format(regex, options = {})
  build_option :format, Coercion.coerce!(regex, Coercion::Regexp), options
end

#url(options = {}) ⇒ Object



24
25
26
# File 'lib/compel/builder/string.rb', line 24

def url(options = {})
  build_option :format, URL_REGEX, options
end