Class: AwesomeUsps::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_usps/location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  @country = options[:country]
  @name = options[:name] || options[:first_name]
  @last_name= options[:last_name]
  @firm_name = options[:firm_name]
  @zip5 = options[:postal_code] || options[:postal] || options[:zip5]
  @zip4 = options[:zip4]
  @state = options[:province] || options[:state]
  @city = options[:city]
  @address1 = options[:address1]
  @address2 = options[:address2]
  @address3=options [:address3]
  @phone = options[:phone]
  @facility_type = options[:facility_type]
  @from_urbanization =options[:from_urbanization]
end

Instance Attribute Details

#address1Object (readonly)

Returns the value of attribute address1.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def address1
  @address1
end

#address2Object (readonly)

Returns the value of attribute address2.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def address2
  @address2
end

#address3Object (readonly)

Returns the value of attribute address3.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def address3
  @address3
end

#cityObject (readonly)

Returns the value of attribute city.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def country
  @country
end

#facility_typeObject (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_nameObject (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_urbanizationObject (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_nameObject (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

#nameObject (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

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def options
  @options
end

#phoneObject (readonly)

Returns the value of attribute phone.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def phone
  @phone
end

#stateObject (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

#zip4Object (readonly)

Returns the value of attribute zip4.



4
5
6
# File 'lib/awesome_usps/location.rb', line 4

def zip4
  @zip4
end

#zip5Object (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, options={})
  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(options))
end

Instance Method Details

#inspectObject



91
92
93
94
# File 'lib/awesome_usps/location.rb', line 91

def inspect
  string = prettyprint
  string
end

#prettyprintObject



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_sObject



79
80
81
# File 'lib/awesome_usps/location.rb', line 79

def to_s
  prettyprint.gsub(/\n/, ' ')
end