Class: FruitToLime::Address

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

get_import_rows, #map_symbol_to_row, #map_to_row, serialize, #serialize, #serialize_to_file, serialize_to_file, serialize_variables, #symbol_to_name

Constructor Details

#initializeAddress

Returns a new instance of Address.



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

def initialize()
end

Instance Attribute Details

#cityObject

Returns the value of attribute city.



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

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



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

def country_code
  @country_code
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#streetObject

Returns the value of attribute street.



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

def street
  @street
end

#zip_codeObject

Returns the value of attribute zip_code.



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

def zip_code
  @zip_code
end

Instance Method Details

#country_nameObject



17
18
19
20
21
22
23
# File 'lib/fruit_to_lime/model/address.rb', line 17

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

#country_name=(name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/fruit_to_lime/model/address.rb', line 24

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

#get_import_rowsObject



12
13
14
15
16
# File 'lib/fruit_to_lime/model/address.rb', line 12

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



34
35
36
# File 'lib/fruit_to_lime/model/address.rb', line 34

def parse_zip_and_address_se(line)
    FruitToLime::AddressHelper::parse_line_to_zip_and_address_se(line, self)
end

#serialize_variablesObject



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

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