Class: Barometer::Query::Format::Zipcode
- Inherits:
-
Barometer::Query::Format
- Object
- Barometer::Query::Format
- Barometer::Query::Format::Zipcode
- Defined in:
- lib/barometer/formats/zipcode.rb
Overview
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 Method Summary collapse
- .convertable_formats ⇒ Object
- .country_code(query = nil) ⇒ Object
- .format ⇒ Object
- .regex ⇒ Object
-
.to(original_query) ⇒ Object
convert to this format, X -> :zipcode.
Methods inherited from Barometer::Query::Format
convert_query, converts?, is?, is_a_query?
Class Method Details
.convertable_formats ⇒ Object
16 |
# File 'lib/barometer/formats/zipcode.rb', line 16 def self.convertable_formats; [:short_zipcode]; end |
.country_code(query = nil) ⇒ Object
14 |
# File 'lib/barometer/formats/zipcode.rb', line 14 def self.country_code(query=nil); "US"; end |
.format ⇒ Object
13 |
# File 'lib/barometer/formats/zipcode.rb', line 13 def self.format; :zipcode; end |
.regex ⇒ Object
15 |
# File 'lib/barometer/formats/zipcode.rb', line 15 def self.regex; /(^[0-9]{5}$)|(^[0-9]{5}-[0-9]{4}$)/; end |
.to(original_query) ⇒ Object
convert to this format, X -> :zipcode
20 21 22 23 24 25 26 27 28 |
# File 'lib/barometer/formats/zipcode.rb', line 20 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 |