Class: USPS::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/USPS/address.rb

Constant Summary collapse

@@input_fields =
{
  'Firm'             => :firm,
  'Urbanization'     => :urbanization,
  'Delivery Address' => :delivery_address,
  'City'             => :city,
  'State'            => :state,
  'Zip Code'         => :zip_code,
}
@@output_fields =
{
  'Carrier Route'   => :carrier_route,
  'County'          => :county,
  'Delivery Point'  => :delivery_point,
  'Check Digit'     => :check_digit,
  'LAC Indicator'   => :lac_indicator,
  'eLOT Sequence'   => :elot_sequence,
  'eLOT Indicator'  => :elot_indicator,
  'Record Type'     => :record_type,
  'PMB Designator'  => :pmb_designator,
  'PMB Number'      => :pmb_number,
  'Default Address' => :default_address,
  'Early Warning'   => :early_warning,
  'Valid'           => :valid,
}
@@field_order =
[
  "Firm",
  "Urbanization",
  "Delivery Address",
  "City",
  "State",
  "Zip Code",
  "Carrier Route",
  "County",
  "Delivery Point",
  "Check Digit",
  "LAC Indicator",
  "eLot Sequence",
  "eLot Indicator",
  "Record Type",
  "PMB Designator",
  "PMB Number",
  "Default Address",
  "Early Warning",
  "Valid",

]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#carrier_routeObject

Returns the value of attribute carrier_route.



147
148
149
# File 'lib/USPS/address.rb', line 147

def carrier_route
  @carrier_route
end

#check_digitObject

Returns the value of attribute check_digit.



147
148
149
# File 'lib/USPS/address.rb', line 147

def check_digit
  @check_digit
end

#cityObject

Returns the value of attribute city.



147
148
149
# File 'lib/USPS/address.rb', line 147

def city
  @city
end

#countyObject

Returns the value of attribute county.



147
148
149
# File 'lib/USPS/address.rb', line 147

def county
  @county
end

#default_addressObject

Returns the value of attribute default_address.



147
148
149
# File 'lib/USPS/address.rb', line 147

def default_address
  @default_address
end

#delivery_addressObject

Returns the value of attribute delivery_address.



147
148
149
# File 'lib/USPS/address.rb', line 147

def delivery_address
  @delivery_address
end

#delivery_pointObject

Returns the value of attribute delivery_point.



147
148
149
# File 'lib/USPS/address.rb', line 147

def delivery_point
  @delivery_point
end

#early_warningObject

Returns the value of attribute early_warning.



147
148
149
# File 'lib/USPS/address.rb', line 147

def early_warning
  @early_warning
end

#elot_indicatorObject

Returns the value of attribute elot_indicator.



147
148
149
# File 'lib/USPS/address.rb', line 147

def elot_indicator
  @elot_indicator
end

#elot_sequenceObject

Returns the value of attribute elot_sequence.



147
148
149
# File 'lib/USPS/address.rb', line 147

def elot_sequence
  @elot_sequence
end

#firmObject

Returns the value of attribute firm.



147
148
149
# File 'lib/USPS/address.rb', line 147

def firm
  @firm
end

#lac_indicatorObject

Returns the value of attribute lac_indicator.



147
148
149
# File 'lib/USPS/address.rb', line 147

def lac_indicator
  @lac_indicator
end

#pmb_designatorObject

Returns the value of attribute pmb_designator.



147
148
149
# File 'lib/USPS/address.rb', line 147

def pmb_designator
  @pmb_designator
end

#pmb_numberObject

Returns the value of attribute pmb_number.



147
148
149
# File 'lib/USPS/address.rb', line 147

def pmb_number
  @pmb_number
end

#record_typeObject

Returns the value of attribute record_type.



147
148
149
# File 'lib/USPS/address.rb', line 147

def record_type
  @record_type
end

#stateObject

Returns the value of attribute state.



147
148
149
# File 'lib/USPS/address.rb', line 147

def state
  @state
end

#urbanizationObject

Returns the value of attribute urbanization.



147
148
149
# File 'lib/USPS/address.rb', line 147

def urbanization
  @urbanization
end

#validObject

Returns the value of attribute valid.



147
148
149
# File 'lib/USPS/address.rb', line 147

def valid
  @valid
end

#zip_codeObject

Returns the value of attribute zip_code.



147
148
149
# File 'lib/USPS/address.rb', line 147

def zip_code
  @zip_code
end

Instance Method Details

#dump(message = nil) ⇒ Object

dump()



301
302
303
# File 'lib/USPS/address.rb', line 301

def dump(message = nil)
  print to_s(message)
end

#fieldsObject

fields()



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/USPS/address.rb', line 248

def fields
  return {
    "Firm" => @firm,
    "Urbanization" => @urbanization,
    "Delivery Address" => @delivery_address,
    "City" => @city,
    "State" => @state,
    "Zip Code" => @zip_code,
    "Carrier Route" => @carrier_route,
    "County" => @county,
    "Delivery Point" => @delivery_point,
    "Check Digit" => @check_digit,
    "LAC Indicator" => @lac_indicator,
    "eLot Sequence" => @elot_sequence,
    "eLot Indicator" => @elot_indicator,
    "Record Type" => @record_type,
    "PMB Designator" => @pmb_designator,
    "PMB Number" => @pmb_number,
    "Default Address" => @default_address,
    "Early Warning" => @early_warning,
    "Valid" => @valid,
  }
end

#query_stringObject



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/USPS/address.rb', line 313

def query_string
  require 'cgi'

  args = [
    [ 'visited'      , '1' ], # NOTE: CGI.escape pukes if this doesn't have quotes. It isn't smart enough to convert to String on its own!
    [ 'pagenumber'   , 'all' ],
    [ 'firmname'      , '' ],
    [ 'address1'     , @delivery_address.upcase ],
#     [ 'address1'     , '' ],
#     [ 'address2'     , addr.delivery_address.upcase ],
    [ 'address2'     , '' ],
    [ 'city'         , @city.upcase ],
    [ 'state'        , @state.upcase ],
    [ 'urbanization' , '' ],
    [ 'zip5'         , @zip_code == nil ? '' : @zip_code.upcase ],
  ]

  result = ''
  
  args.each { |arg|
    key = arg[0]
    value = arg[1]
    
    if value == nil
      raise "Value is nil for key '" + key + "'!!!"
    end
    
    value = CGI.escape(arg[1])
    
    temp = sprintf("%s=%s", key, value)
    
    if result != ''
      result += "&"
    end
    
    result += temp
  }
  
  return result
end

#to_dumpObject

to_dump()



309
310
311
# File 'lib/USPS/address.rb', line 309

def to_dump
  return to_s()
end

#to_s(message = nil) ⇒ Object

to_s()



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/USPS/address.rb', line 276

def to_s(message = nil)
  output = ''
  
  if message != nil
    output = sprintf "ADDRESS: %s\n", message
  end

  temp = fields

  @@field_order.each { |key|
    value = temp[key]
    next if value == nil
    line = sprintf "  %s => '%s'\n", key, value
    output += line
  }

  output += "\n"

  return output
end