Sha256: 356b128ca83890397c6701c343e65ef6fd0b4c08f7f741fc8c0fd5b0d7362bc6

Contents?: true

Size: 956 Bytes

Versions: 4

Compression:

Stored size: 956 Bytes

Contents

# frozen_string_literal: true

class Gman
  # Second level .us domains for states and locality
  # See http://en.wikipedia.org/wiki/.us
  #
  # Examples:
  #  * foo.state.il.us
  #  * ci.foo.il.us
  #
  # Not:
  #  * state.foo.il.us
  #  * foo.ci.il.us
  #  * k12.il.us
  #  * ci.foo.zx.us
  class Locality
    AFFINITY_NAMESPACES = %w[state dst cog].freeze

    STATES = %w[
      ak al ar az ca co ct dc de fl ga hi ia id il in ks ky
      la ma md me mi mn mo ms mt nc nd ne nh nj nm nv ny oh
      ok or pa ri sc sd tn tx um ut va vt wa wi wv wy
    ].freeze

    LOCALITY_DOMAINS = %w[
      ci co borough boro city county
      parish town twp vi vil village
    ].freeze

    REGEX = /
      (
        (#{Regexp.union(AFFINITY_NAMESPACES)})
      |
        (#{Regexp.union(LOCALITY_DOMAINS)})\.[a-z-]+
      )\.(#{Regexp.union(STATES)})\.us
    /x.freeze

    def self.valid?(domain)
      !domain.to_s.match(Locality::REGEX).nil?
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gman-7.0.6 lib/gman/locality.rb
gman-7.0.5 lib/gman/locality.rb
gman-7.0.4 lib/gman/locality.rb
gman-7.0.3 lib/gman/locality.rb