Class: Lobbyliste::Factories::ListFactory
- Defined in:
- lib/lobbyliste/factories/list_factory.rb
Overview
This class is used to build the list from raw data
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #abbreviations ⇒ Object
-
#initialize(text_data, html_data) ⇒ ListFactory
constructor
A new instance of ListFactory.
- #last_update ⇒ Object
- #names ⇒ Object
- #organisations ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(text_data, html_data) ⇒ ListFactory
Returns a new instance of ListFactory.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 18 def initialize(text_data,html_data) @text_data = text_data @html_data = html_data @lines = text_data.each_line.to_a.map(&:chomp) @organisations = nil = nil @abbreviations = nil @names = nil end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 5 def data @data end |
Class Method Details
.build(text_data, html_data) ⇒ Lobbyliste::List
8 9 10 11 12 13 14 15 16 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 8 def self.build(text_data,html_data) factory = new(text_data,html_data) ::Lobbyliste::List.new( factory.organisations, factory., factory.abbreviations, factory.last_update ) end |
Instance Method Details
#abbreviations ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 68 def abbreviations return @abbreviations if @abbreviations abbreviations = Hash.new{|h,k| h[k] = []} current_abbr = "A" extract_abbreviation_data.each do |line| if line.match(/^[A-ZÄÖÜ][A-ZÄÖÜa-zäöüß]+$/) && [current_abbr[0],current_abbr[0].next].include?(line[0]) current_abbr = line elsif line.match(/^\– \d+/) id = line.match(/^\– (\d+)/)[1].to_i abbreviations[current_abbr] << id end end @abbreviations = abbreviations end |
#last_update ⇒ Object
84 85 86 87 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 84 def last_update date = @text_data.match(/^Stand: (\d\d\.\d\d\.\d\d\d\d)/) Date.parse(date[1]) end |
#names ⇒ Object
42 43 44 45 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 42 def names extract_names unless @names @names end |
#organisations ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 30 def organisations return @organisations if @organisations @organisations = organisations_data.map do |organisation_data| id = organisation_data[0].to_i name = names[id] = (id) abbreviations = abbreviations_for_organisation(id) ::Lobbyliste::Factories::OrganisationFactory.build(name,organisation_data,,abbreviations) end end |
#tags ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lobbyliste/factories/list_factory.rb', line 48 def return if = Hash.new{|h,k| h[k] = []} tag_data = extract_tag_data current_tag = "A" tag_data.each do |line| if line.match(/^[A-ZÄÖÜ][a-zäöüß]+$/) && [current_tag[0],current_tag[0].next].include?(line[0]) current_tag = line elsif line.match(/^\– \d+/) id = line.match(/^\– (\d+)/)[1].to_i [current_tag] << id end end = end |