Sha256: e09de884551e05e4c77d69250beaf91d9e14dc9b405a7ef0451623c557a34361

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

module Rubymisc
  module Regex
    autoload :Manual, File.expand_path('../regex/manual', __FILE__)

    class << self
      def email
        email_name_regex  = '[\w\.%\+\-]+'.freeze
        domain_head_regex = '(?:[A-Z0-9\-]+\.)+'.freeze
        domain_tld_regex  = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'.freeze
        /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
      end

      def url
        /\A((https?):(([A-Za-z0-9$_.+!*(),;\/?:@&~=-])|%[A-Za-z0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;\/?:@&~=%-]*))?([A-Za-z0-9$_+!*();\/?:~-]))\z/
      end

      def zip
        /\A\d{5}(?:-\d{4})?\z/
      end

      def ipv4
        ip_octet = '(\d|[01]?\d\d|2[0-4]\d|25[0-5])'.freeze
        /\A#{ip_octet}\.#{ip_octet}\.#{ip_octet}\.#{ip_octet}\z/
      end

      def mac_address
        /\A(\h{2}:){5}\h{2}\z/
      end

      def hexcode
        /\A#(\h{3}){1,2}\z/
      end

      def usd
        /\A\$(\d{1,3}(\,\d{3})*|\d+)(\.\d{2})?\z/
      end
    end

    code = <<-CODE
      def man; Manual.man; end
    CODE

    singleton_class.module_eval code
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubymisc-0.0.4 lib/rubymisc/regex.rb
rubymisc-0.0.3.3 lib/rubymisc/regex.rb