Class: GoImport::Address

Inherits:
Object
  • Object
show all
Includes:
SerializeHelper
Defined in:
lib/go_import/model/address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

#serialize, #serialize_to_file

Constructor Details

#initializeAddress

Returns a new instance of Address.



9
10
# File 'lib/go_import/model/address.rb', line 9

def initialize()
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



4
5
6
# File 'lib/go_import/model/address.rb', line 4

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



4
5
6
# File 'lib/go_import/model/address.rb', line 4

def country_code
  @country_code
end

#locationObject

Returns the value of attribute location.



4
5
6
# File 'lib/go_import/model/address.rb', line 4

def location
  @location
end

#streetObject

Returns the value of attribute street.



4
5
6
# File 'lib/go_import/model/address.rb', line 4

def street
  @street
end

#zip_codeObject

Returns the value of attribute zip_code.



4
5
6
# File 'lib/go_import/model/address.rb', line 4

def zip_code
  @zip_code
end

Instance Method Details

#country_nameObject

Used as a convenience in order to get country code from internally used #country_code



20
21
22
23
24
25
26
# File 'lib/go_import/model/address.rb', line 20

def country_name
    if @country_code
        IsoCountryCodes.find(@country_code).name
    else
        nil
    end
end

#country_name=(name) ⇒ Object

Used as a convenience in order to map country name to the internal #country_code



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/go_import/model/address.rb', line 29

def country_name=(name)
    @country_code = case name
    when nil
        nil
    when 'Sverige'
        'SE'
    else
        begin
            IsoCountryCodes.search_by_name(name).first.alpha2
        rescue
            nil
        end
    end
end

#get_import_rowsObject

What fields/rows on the class is supposed to be used by the Gem to generate the xml This method uses #serialize_variables. It also adds #country_name to be serialized



14
15
16
17
18
# File 'lib/go_import/model/address.rb', line 14

def get_import_rows
    (serialize_variables+[{:id=>:country_name, :type=>:string}]).map do |p|
        map_to_row p
    end
end

#parse_zip_and_address_se(line) ⇒ Object

parses a line like “226 48 LUND” into its corresponding zipcode and city properties on the address



45
46
47
# File 'lib/go_import/model/address.rb', line 45

def parse_zip_and_address_se(line)
    Address.parse_line_to_zip_and_address_se(line, self)
end

#serialize_variablesObject



5
6
7
# File 'lib/go_import/model/address.rb', line 5

def serialize_variables
    [ :street, :zip_code, :city, :country_code, :location].map {|p| {:id=>p,:type=>:string} }
end