Sha256: 74e1385d7e3a1448882bd93802f9295e1427ad63e0c9e6df19287eb6024d67ec

Contents?: true

Size: 895 Bytes

Versions: 14

Compression:

Stored size: 895 Bytes

Contents

module Barometer
  #
  # Format: Zip Code
  #
  # eg. 90210 or 90210-5555
  #
  # This class is used to determine if a query is a
  # :zip_code, how to convert to a :zip_code
  # and what the country_code is.
  #
  class Query::Format::Zipcode < Query::Format
  
    def self.format; :zipcode; end
    def self.country_code(query=nil); "US"; end
    def self.regex; /(^[0-9]{5}$)|(^[0-9]{5}-[0-9]{4}$)/; end
    def self.convertable_formats; [:short_zipcode]; end

    # convert to this format, X -> :zipcode
    #
    def self.to(original_query)
      raise ArgumentError unless is_a_query?(original_query)
      return nil unless converts?(original_query)
      converted_query = Barometer::Query.new
      converted_query.q = original_query.q
      converted_query.format = format
      converted_query.country_code = country_code(converted_query.q)
      converted_query
    end
  
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
attack-barometer-0.5.0 lib/barometer/formats/zipcode.rb
attack-barometer-0.6.0 lib/barometer/formats/zipcode.rb
attack-barometer-0.6.1 lib/barometer/formats/zipcode.rb
barometer-0.7.3 lib/barometer/formats/zipcode.rb
barometer-0.7.2 lib/barometer/formats/zipcode.rb
barometer-0.7.1 lib/barometer/formats/zipcode.rb
barometer-0.7.0 lib/barometer/formats/zipcode.rb
barometer-0.6.7 lib/barometer/formats/zipcode.rb
barometer-0.6.6 lib/barometer/formats/zipcode.rb
barometer-0.6.4 lib/barometer/formats/zipcode.rb
barometer-0.6.3 lib/barometer/formats/zipcode.rb
barometer-0.6.2 lib/barometer/formats/zipcode.rb
barometer-0.6.1 lib/barometer/formats/zipcode.rb
barometer-0.5.0 lib/barometer/formats/zipcode.rb