Class: Lobbyliste::Factories::AddressFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/lobbyliste/factories/address_factory.rb

Overview

This class is used to build an address from raw data Since it is to hard to separate the na,e and address data without markup, we use the html data to accomplish that

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, raw_data, type = :primary) ⇒ AddressFactory

Returns a new instance of AddressFactory.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lobbyliste/factories/address_factory.rb', line 27

def initialize(name,raw_data,type=:primary)
  @name = name
  @raw_data = raw_data

  @address = []
  @tel = nil
  @fax = nil
  @website = nil
  @email = nil
  @country = "Deutschland"
  @postcode = nil
  @city = nil
  @type=type

  parse
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def city
  @city
end

#countryObject (readonly)

Returns the value of attribute country.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def country
  @country
end

#emailObject (readonly)

Returns the value of attribute email.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def email
  @email
end

#faxObject (readonly)

Returns the value of attribute fax.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def fax
  @fax
end

#nameObject (readonly)

Returns the value of attribute name.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def name
  @name
end

#postcodeObject (readonly)

Returns the value of attribute postcode.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def postcode
  @postcode
end

#telObject (readonly)

Returns the value of attribute tel.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def tel
  @tel
end

#typeObject (readonly)

Returns the value of attribute type.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def type
  @type
end

#websiteObject (readonly)

Returns the value of attribute website.



25
26
27
# File 'lib/lobbyliste/factories/address_factory.rb', line 25

def website
  @website
end

Class Method Details

.build(name, raw_data, type = :primary) ⇒ Lobbyliste::Address

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lobbyliste/factories/address_factory.rb', line 9

def self.build(name,raw_data, type=:primary)
  factory = new(name,raw_data,type)
  ::Lobbyliste::Address.new(
    factory.name,
    factory.address,
    factory.postcode,
    factory.city,
    factory.country,
    factory.tel,
    factory.fax,
    factory.website,
    factory.email,
    factory.type
  )
end

Instance Method Details

#addressObject



58
59
60
# File 'lib/lobbyliste/factories/address_factory.rb', line 58

def address
  @address.join(", ")
end

#parseObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lobbyliste/factories/address_factory.rb', line 44

def parse
  @raw_data.each_with_index do |line,i|
    case label(line,i)
      when :addr then @address << line
      when :tel then extract_tel_fax(line)
      when :postcode then extract_postcode_city(line)
      when :email then extract_email(line)
      when :website then extract_website(line)
      when :country then @country = line
      else next
    end
  end
end