class Lobbyliste::Factories::PersonFactory
This class is used to build a person from raw line data It has to split titles from the actual name
Constants
- REGEX
A list of regular expressions that try to match any titles that might occur
Public Class Methods
build(raw_data)
click to toggle source
@return [Lobbylist::Person] builds a new person, might be nil if the line does not represent a person
# File lib/lobbyliste/factories/person_factory.rb, line 34 def self.build(raw_data) factory = new(raw_data) factory.is_person? ? ::Lobbyliste::Person.new(factory.name,factory.titles,raw_data) : nil end
new(raw_data)
click to toggle source
# File lib/lobbyliste/factories/person_factory.rb, line 39 def initialize(raw_data) @raw_data = raw_data @name = nil end
Public Instance Methods
is_person?()
click to toggle source
# File lib/lobbyliste/factories/person_factory.rb, line 59 def is_person? !name.nil? && name.length > 2 && name.include?(" ") end
name()
click to toggle source
# File lib/lobbyliste/factories/person_factory.rb, line 44 def name return @name if @name @name = @raw_data.dup REGEX.each do |regex| @name = clean(@name.gsub(regex,"")) end @name end
titles()
click to toggle source
# File lib/lobbyliste/factories/person_factory.rb, line 55 def titles @raw_data.gsub(name,"").split(", ").map(&:squish).reject{|x| x==""} end
Private Instance Methods
clean(string)
click to toggle source
# File lib/lobbyliste/factories/person_factory.rb, line 65 def clean(string) string.gsub(/^(\s*[,-:\(\)\|\.])*/,"").squish end