Sha256: 6da2e7568ea7051cad8bb1556603cc3d3c34d0756d5ec525fb03266b466919ec

Contents?: true

Size: 864 Bytes

Versions: 4

Compression:

Stored size: 864 Bytes

Contents

module Compel
  module Builder

    class String < Schema

      # Taken from ruby_regex gem by @eparreno
      # https://github.com/eparreno/ruby_regex
      URL_REGEX = /(\A\z)|(\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\z)/ix

      # Taken from Michael Hartl's 'The Ruby on Rails Tutorial'
      # https://www.railstutorial.org/book
      EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i

      include CommonValue

      def initialize
        super(Coercion::String)
      end

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

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

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

    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
compel-0.5.1 lib/compel/builder/string.rb
compel-0.5.0 lib/compel/builder/string.rb
compel-0.4.3 lib/compel/builder/string.rb
compel-0.4.2 lib/compel/builder/string.rb