# File lib/governator/governor.rb, line 40 def primary_office @_primary_office ||= office end
class Governator::Governor
Instance methods included in the Governator
class
Attributes
office_locations[R]
official_full[R]
panel[R]
parsed_name[R]
party[R]
state_name[R]
twitter[R]
url[R]
Public Class Methods
create(panel)
click to toggle source
# File lib/governator/governor.rb, line 11 def self.create(panel) new(panel).tap do |g| g.send :build g.send :save end end
new(panel)
click to toggle source
Initializes a new Governator
instance
@param panel [Governator::Panel] the Panel
scraper object to pull the Governor's data from
# File lib/governator/governor.rb, line 21 def initialize(panel) @panel = panel end
Public Instance Methods
contact_form()
click to toggle source
# File lib/governator/governor.rb, line 52 def contact_form civil_services.contact_form end
facebook()
click to toggle source
# File lib/governator/governor.rb, line 48 def facebook civil_services.facebook end
first_name()
click to toggle source
# File lib/governator/governor.rb, line 56 def first_name parsed_name.first_name end
inspect()
click to toggle source
# File lib/governator/governor.rb, line 32 def inspect "#<Governator #{official_full}>" end
last_name()
click to toggle source
# File lib/governator/governor.rb, line 68 def last_name parsed_name.last_name end
middle_name()
click to toggle source
# File lib/governator/governor.rb, line 60 def middle_name parsed_name.middle_name end
nickname()
click to toggle source
# File lib/governator/governor.rb, line 64 def nickname parsed_name.nickname end
photo_url()
click to toggle source
# File lib/governator/governor.rb, line 44 def photo_url civil_services.photo_url || Governator::BASE_URI + panel.image end
primary_office()
click to toggle source
secondary_office()
click to toggle source
# File lib/governator/governor.rb, line 36 def secondary_office @_secondary_office ||= office(prefix: :alt_) end
suffix()
click to toggle source
# File lib/governator/governor.rb, line 72 def suffix parsed_name.suffix end
to_h()
click to toggle source
# File lib/governator/governor.rb, line 25 def to_h syms = %i[photo_url state_name official_full url party office_locations] syms.each_with_object({}) do |sym, hsh| hsh[sym] = send(sym) end end
Private Instance Methods
bio_page()
click to toggle source
# File lib/governator/governor.rb, line 97 def bio_page @_bio_page ||= Governator::BioPage.new(panel.bio_page) end
build()
click to toggle source
# File lib/governator/governor.rb, line 85 def build @state_name = panel.state @official_full = panel.governor_name @url = bio_page.website @party = bio_page.party @parsed_name = Governator::NameParser.new(official_full).parse build_office_locations fetch_twitter_handle self end
build_office_locations()
click to toggle source
# File lib/governator/governor.rb, line 120 def build_office_locations @office_locations = [primary_office] @office_locations << secondary_office if bio_page.alt_office_present? end
check_twitter_client_for_handle()
click to toggle source
# File lib/governator/governor.rb, line 110 def check_twitter_client_for_handle twitter_governor = Governator::TwitterClient.governors.detect do |tg| tg[:name].match(last_name) && ( tg[:location].match(state_name) || tg[:description].match(state_name) ) end @twitter = twitter_governor[:screen_name] if twitter_governor end
civil_services()
click to toggle source
# File lib/governator/governor.rb, line 101 def civil_services @_civil_services ||= Governator::CivilServices.new(self) end
fetch_twitter_handle()
click to toggle source
# File lib/governator/governor.rb, line 105 def fetch_twitter_handle check_twitter_client_for_handle if Governator::Config.use_twitter? @twitter = civil_services.twitter if twitter.nil? end
office(prefix: nil)
click to toggle source
# File lib/governator/governor.rb, line 78 def office(prefix: nil) syms = %i[address city state zip phone fax office_type] syms.each_with_object(Governator::Office.new) do |sym, office| office[sym] = bio_page.send("#{prefix}#{sym}") end end
save()
click to toggle source
# File lib/governator/governor.rb, line 125 def save Governator.governors << self self end