class Lobbyliste::Factories::OrganisationFactory

This class is used to build an organisation from raw data

Attributes

name[R]

Public Class Methods

build(name, raw_data,tags,abbreviations) click to toggle source

@return [Lobbyliste::Organisation]

# File lib/lobbyliste/factories/organisation_factory.rb, line 8
def self.build(name, raw_data,tags,abbreviations)
  factory = new(name, raw_data)
  ::Lobbyliste::Organisation.new(
      factory.id,
      factory.name,
      factory.address,
      factory.additional_address,
      factory.address_at_bt_br,
      factory.people,
      factory.interests,
      factory.members,
      factory.associated_organisations,
      tags,
      abbreviations
  )
end
new(name,raw_data) click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 27
def initialize(name,raw_data)
  @name = name
  @raw_data = raw_data
end

Public Instance Methods

additional_address() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 42
def additional_address
  data = read_section("W e i t e r e A d r e s s e")
  return nil if data[0] == "–"
  AddressFactory.build(name, data, :secondary)
end
address() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 37
def address
  data = read_section("N a m e u n d S i t z , 1 . A d r e s s e")
  AddressFactory.build(name, data, :primary)
end
address_at_bt_br() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 48
def address_at_bt_br
  data = read_section("A n s c h r i f t a m S i t z v o n B T u n d B R g")
  return nil if data[0] == "–" || data[0].match(/\(s\. Abschnitt/)
  AddressFactory.build(name, data, :secondary)
end
associated_organisations() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 89
def associated_organisations
  read_section("A n z a h l d e r a n g e s c h l o s s e n e n O r g a n i s a t i o n e n")[0].to_i || nil
end
id() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 32
def id
  @raw_data.first.to_i
end
interests() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 62
def interests
  interest_lines = read_section("I n t e r e s s e n b e r e i c h").dup


  (0..interest_lines.count-1).each do |i|
    line = interest_lines[i]
    next_line = interest_lines[i+1]

    if line =~ /[-–]$/ && !(next_line.start_with?("und"," und", "oder", " oder"))
      line.gsub!(/[-–]$/,"")
      next_line_words = next_line.split(" ")

      line += next_line_words.slice!(0)
      next_line = next_line_words.join(" ")
    end

    interest_lines[i] = line
    interest_lines[i+1] = next_line
  end

  interest_lines.reject(&:blank?).join("\n")
end
members() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 85
def members
  read_section("M i t g l i e d e r z a h l")[0].to_i || nil
end
people() click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 54
def people
  data = read_section("V o r s t a n d u n d G e s c h ä f t s f ü h r u n g")
  data.concat read_section("V e r b a n d s v e r t r e t e r / - i n n e n")
  data.reject! {|line| ignored_person_line?(line)}

  data.map { |person| PersonFactory.build(person) }.uniq.reject(&:nil?)
end

Private Instance Methods

ignored_person_line?(line) click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 107
def ignored_person_line?(line)
  [
    /^–$/,
    /\(s\. Abschnitt/,
    /\:$/,
    /^GdW$/,
    /^Forschung$/,
    /^des Verwaltungsrats$/,
    /^Schatzmeister$/,
    /^Kinder- u\. Jugendmed\.$/,
    /^u\. Kinderchirurgen$/,
    /^Finanzen & Recht I$/,
    /^Geschäftsführ(er(in)?|ung)$/,
    /^gleichzeitig Verbandsdirektor^/,
    /^(stellvertretender )?Vorsitzender?$/,
    /^weitere Vorstandsmitglieder$/,
    /^Managementgesellschaft des DZVhÄ/,
    /^Besonderer Vertreter nach § 30/,
    /^Sektretär$/,
    /^Alleingesellschafter: Ev\.Werk für/
  ].any? {|regexp| line.match(regexp) }
end
new_section?(line) click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 96
def new_section?(line)
   line =~ /^([a-zA-Z\d\,\.\-\/äöüß]\s){3,}\w$/
end
read_section(section) click to toggle source
# File lib/lobbyliste/factories/organisation_factory.rb, line 100
def read_section(section)
  start_line = @raw_data.index {|line| line == section}
  return [] unless start_line

  @raw_data.drop(start_line+1).take_while {|line| !new_section?(line)}
end