Class: AwesomeUsps::Location
- Inherits:
-
Object
- Object
- AwesomeUsps::Location
- Defined in:
- lib/awesome_usps/location.rb
Instance Attribute Summary collapse
-
#address1 ⇒ Object
readonly
Returns the value of attribute address1.
-
#address2 ⇒ Object
readonly
Returns the value of attribute address2.
-
#address3 ⇒ Object
readonly
Returns the value of attribute address3.
-
#city ⇒ Object
readonly
Returns the value of attribute city.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#facility_type ⇒ Object
readonly
Returns the value of attribute facility_type.
-
#firm_name ⇒ Object
readonly
Returns the value of attribute firm_name.
-
#from_urbanization ⇒ Object
readonly
Returns the value of attribute from_urbanization.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#name ⇒ Object
(also: #first_name)
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#phone ⇒ Object
readonly
Returns the value of attribute phone.
-
#state ⇒ Object
(also: #province)
readonly
Returns the value of attribute state.
-
#zip4 ⇒ Object
readonly
Returns the value of attribute zip4.
-
#zip5 ⇒ Object
(also: #postal_code)
readonly
Returns the value of attribute zip5.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Location
constructor
A new instance of Location.
- #inspect ⇒ Object
- #prettyprint ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Location
Returns a new instance of Location.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/awesome_usps/location.rb', line 30 def initialize( = {}) @country = [:country] @name = [:name] || [:first_name] @last_name= [:last_name] @firm_name = [:firm_name] @zip5 = [:postal_code] || [:postal] || [:zip5] @zip4 = [:zip4] @state = [:province] || [:state] @city = [:city] @address1 = [:address1] @address2 = [:address2] @address3= [:address3] @phone = [:phone] @facility_type = [:facility_type] @from_urbanization =[:from_urbanization] end |
Instance Attribute Details
#address1 ⇒ Object (readonly)
Returns the value of attribute address1.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def address1 @address1 end |
#address2 ⇒ Object (readonly)
Returns the value of attribute address2.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def address2 @address2 end |
#address3 ⇒ Object (readonly)
Returns the value of attribute address3.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def address3 @address3 end |
#city ⇒ Object (readonly)
Returns the value of attribute city.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def city @city end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def country @country end |
#facility_type ⇒ Object (readonly)
Returns the value of attribute facility_type.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def facility_type @facility_type end |
#firm_name ⇒ Object (readonly)
Returns the value of attribute firm_name.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def firm_name @firm_name end |
#from_urbanization ⇒ Object (readonly)
Returns the value of attribute from_urbanization.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def from_urbanization @from_urbanization end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def last_name @last_name end |
#name ⇒ Object (readonly) Also known as: first_name
Returns the value of attribute name.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def end |
#phone ⇒ Object (readonly)
Returns the value of attribute phone.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def phone @phone end |
#state ⇒ Object (readonly) Also known as: province
Returns the value of attribute state.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def state @state end |
#zip4 ⇒ Object (readonly)
Returns the value of attribute zip4.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def zip4 @zip4 end |
#zip5 ⇒ Object (readonly) Also known as: postal_code
Returns the value of attribute zip5.
4 5 6 |
# File 'lib/awesome_usps/location.rb', line 4 def zip5 @zip5 end |
Class Method Details
.from(object, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/awesome_usps/location.rb', line 47 def self.from(object, ={}) return object if object.is_a? FotoVerite::Location attr_mappings = { :name => [:name, :first_name], #:country => [:country_code, :country], :zip5 => [:postal_code, :zip5, :postal], :zip4 => [:zip4], :state => [ :province, :state], :city => [:city], :address1 => [:address1], :address2 => [:address2], :facility_type => [:facility_type] } attributes = {} hash_access = begin object[:some_symbol] true rescue false end attr_mappings.each do |pair| pair[1].each do |sym| if value = (object[sym] if hash_access) || (object.send(sym) if object.respond_to?(sym) && (!hash_access || !Hash.public_instance_methods.include?(sym.to_s))) attributes[pair[0]] = value break end end end self.new(attributes.update()) end |
Instance Method Details
#inspect ⇒ Object
91 92 93 94 |
# File 'lib/awesome_usps/location.rb', line 91 def inspect string = prettyprint string end |
#prettyprint ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/awesome_usps/location.rb', line 83 def prettyprint chunks = [] chunks << [@name,@firm_name].reject {|e| e.blank?}.join("\n") chunks << [@address1,@address2].reject {|e| e.blank?}.join("\n") chunks << [@city,@state,@zip5].reject {|e| e.blank?}.join(', ') chunks.reject {|e| e.blank?}.join("\n") end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/awesome_usps/location.rb', line 79 def to_s prettyprint.gsub(/\n/, ' ') end |