Sha256: 2b1c91e33cf725c75b7b64e571f3678d7d93f0e8b725544bd987b2e468841b58

Contents?: true

Size: 970 Bytes

Versions: 9

Compression:

Stored size: 970 Bytes

Contents

module SmartRspec
  module Support
    module Regexes
      @@uri_regexes =
        { protocol: /((ht|f)tp[s]?)/i,
          uri: %r{^(
                (((ht|f)tp[s]?://)|([a-z0-9]+\.))+
                (?<!@)
                ([a-z0-9\_\-]+)
                (\.[a-z]+)+
                ([\?/\:][a-z0-9_=%&@\?\./\-\:\#\(\)]+)?
                /?
              )$}ix }

      def build_regex(type, *args)
        case type.to_sym
        when :email then /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
        when :image then build_img_regex(args)
        else @@uri_regexes[type]
        end
      end

      private_class_method

      def build_img_regex(exts = [])
        exts = [exts].flatten
        if exts.nil? || exts.empty?
          exts = %w(jpg jpeg png gif)
        elsif exts.include?(:jpg) && !exts.include?(:jpeg)
          exts.push :jpeg
        end
        %r{(^http{1}[s]?://([w]{3}\.)?.+\.(#{exts.join('|')})(\?.+)?$)}i
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
smart_rspec-0.2.0 lib/smart_rspec/support/regexes.rb
smart_rspec-0.1.6 lib/smart_rspec/support/regexes.rb
smart_rspec-0.1.5 lib/smart_rspec/support/regexes.rb
smart_rspec-0.1.4 lib/smart_rspec/support/regexes.rb
smart_rspec-0.1.3 lib/smart_rspec/support/regexes.rb
smart_rspec-0.1.2 lib/smart_rspec/support/regexes.rb
smart_rspec-0.1.1 lib/smart_rspec/support/regexes.rb
smart_rspec-0.1.0 lib/smart_rspec/support/regexes.rb
smart_rspec-0.0.2 lib/smart_rspec/support/regexes.rb