Sha256: 94a1a86e290c6766d961eebf6d84d8ddbe6f8bbaa0758a172d54632c9dcdb44d
Contents?: true
Size: 1.24 KB
Versions: 9
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true module GetYourRep # Office information. Belongs to Representative. class OfficeLocation include GetYourRep::Errors # Each instance belongs to a Represenative, which has many OfficeLocations. attr_accessor :rep # Defines the type of office ('district' or 'capitol') attr_accessor :type # Line 1 of address. attr_accessor :line_1 # Line 2 of address. attr_accessor :line_2 # City, state and zip. attr_accessor :city, :state, :zip # Construct a new instance, setting attributes from an options hash. def initialize(office_hash = {}) office_hash.each do |key, val| send("#{key}=", val) end end # Set the rep attribute to an instance of a Representative, and make two-way association. def rep=(other) if other.is_a?(Representative) @rep = other other.add_office_location(self) unless other.office_locations.include?(self) else not_a_rep_error end end # Display self attributes for CLI. def cli_display puts " #{type.capitalize} Office".bold.blue office_lines = [line_1, line_2, "#{city}, #{state} #{zip}"] office_lines.each { |line| puts " #{line}".red if line } end end end
Version data entries
9 entries across 9 versions & 1 rubygems