Sha256: efc7c1d328b89631a699f025008bf9cce1a5db25103d27c52988be486f088ea7

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module VoteSmart
  
  class District < Common
    
    attr_accessor :id, :name, :office_id, :state_id
    
    attr_accessor :office
    
    set_attribute_map "districtId" => :id, "name" => :name, "officeId" => :office_id, "stateId" => :state_id
    
    def number
      return unless name
      
      scan = name.scan(/District (\d[0-9]*)/) || []
      scan = scan.first || []
      num = scan.first
      num ? num.to_i : nil
    end
    
    def official
      @official ||= Official.find_by_district(self)
    end
    
    def self.find_all_by_office_and_state office, state
      find_all_by_office_id_and_state_id(office.id, state.id)
    end
    
    def self.find_all_by_office_id_and_state_id office_id, state_id
      response_child(get_by_office_state(office_id, state_id), "districtList", "district").collect {|attributes| District.new(attributes)}
    end
    
    # Returns districts service the office and state provided
    def self.get_by_office_state office_id, state_id = 'NA', district_name = ''
      request("District.getByOfficeState", "officeId" => office_id, "stateId" => state_id, "districtName" => district_name)
    end
    
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
netroots-ruby-votesmart-0.2.2 lib/vote_smart/district.rb
netroots-ruby-votesmart-0.2.3 lib/vote_smart/district.rb
netroots-ruby-votesmart-0.2.4 lib/vote_smart/district.rb
votesmart-0.3.0 lib/vote_smart/district.rb