module GetYourRep # Stores rep info in key/value pairs, and makes values accessible by instance method. class Representative < Hash # Maps attributes to a simple array for easy printing, iteration, and display. It uses #each rather than #map so it can skip over nil values without mapping them. def business_card card = [] self.each do |key, value| next if value.nil? if key == :facebook || key == :twitter || key == :youtube || key == :googleplus card << "#{key.to_s.capitalize}: #{value}" else card << "#{value}" end end card end # Get the :name value. def name @name = self[:name] end # Set the :name value. def name=(value) @name = value self[:name] = @name end # Strips the first name out of the full name if there's no :first_name. def first_name return self[:first_name] if self[:first_name] if (name.split.count > 3) || (name.split[-2].downcase == name.split[-2]) name.split[0..-3].join(' ') else name.split[0..-2].join(' ') end end # Get the :middle_name value. def middle_name @middle_name = self[:middle_name] end # Strips the surname out of the full name if there's no :last_name. def last_name return self[:last_name] if self[:last_name] if (name.split.count > 3) || (name.split[-2].downcase == name.split[-2]) name.split[-2..-1].join(' ') else name.split.last end end # Get the :office value. def office @office = self[:office] end # Set the :office value. def office=(value) @office = value self[:office] = @office end # Get the :party value. def party @party = self[:party] end # Set the :party value. def party=(value) @party = value self[:party] = @party end # Get the :phone value. def phone @phone = self[:phone] end # Set the :phone value. def phone=(value) @phone = value self[:phone] = @phone end # Get the :alt_phone value. # def alt_phone # @alt_phone = self[:alt_phone] # end # Set the :alt_phone value. # def alt_phone=(value) # @alt_phone = value # self[:alt_phone] = @alt_phone # end # Get the :alt_address_1 value. # def alt_address_1 # @alt_address_1 = self[:alt_address_1] # end # Set the :alt_address_1 value. # def alt_address_1=(value) # @alt_address_1 = value # self[:alt_address_1] = @alt_address_1 # end # Get the :alt_address_2 value. # def alt_address_2 # @alt_address_2 = self[:alt_address_2] # end # Set the :alt_address_2 value. # def alt_address_2=(value) # @alt_address_2 = value # self[:alt_address_2] = @alt_address_2 # end # Get the :alt_address_3 value. # def alt_address_3 # @alt_address_3 = self[:alt_address_3] # end # Set the :alt_address_3 value. # def alt_address_3=(value) # @alt_address_3 = value # self[:alt_address_3] = @alt_address_3 # end # Get the :address_1 value. # def address_1 # @address_1 = self[:address_1] # end # Set the :address_1 value. # def address_1=(value) # @address_1 = value # self[:address_1] = @address_1 # end # Get the :address_2 value. # def address_2 # @address_2 = self[:address_2] # end # Set the :address_2 value. # def address_2=(value) # @address_2 = value # self[:address_2] = @address_2 # end # Get the :address_3 value. # def address_3 # @address_3 = self[:address_3] # end # Set the :address_3 value. # def address_3=(value) # @address_3 = value # self[:address_3] = @address_3 # end def office_locations @office_locations = self[:office_locations] end def office_locations=(value) @office_locations = value self[:office_locations] = @office_locations end def district_office @district_office = self.office_locations.select { |loc| loc[:type] == 'district' }.first {} if @district_office.nil? end def capitol_office @capitol_office = self.office_locations.select { |loc| loc[:type] == 'capitol' }.first {} if @capitol_office.nil? end # Get the :email value. def email @email = self[:email] end # Set the :email value. def email=(value) @email = value self[:email] = @email end # Get the :committees value. def committees @committees = self[:committees] end # Set the :committees value. def committees=(value) @committees = value self[:committees] = @committees end # Get the :url value. def url @url = self[:url] end # Set the :url value. def url=(value) @url = value self[:url] = @url end # Get the :photo value. def photo @photo = self[:photo] end # Set the :photo value. def photo=(value) @photo = value self[:photo] = @photo end # Get the :twitter value. def twitter @twitter = self[:twitter] end # Set the :twitter value. def twitter=(value) @twitter = value self[:twitter] = @twitter end # Get the :facebook value. def facebook @facebook = self[:facebook] end # Set the :facebook value. def facebook=(value) @facebook = value self[:facebook] = @facebook end # Get the :youtube value. def youtube @youtube = self[:youtube] end # Set the :youtube value. def youtube=(value) @youtube = value self[:youtube] = @youtube end # Get the :googleplus value. def googleplus @googleplus = self[:googleplus] end # Set the :googleplus value. def googleplus=(value) @googleplus = value self[:googleplus] = @googleplus end end end