Sha256: 903c748fa8ebbece42760b3e2c4361c2a19cf1b65af9ac890b20bc30112eb316

Contents?: true

Size: 790 Bytes

Versions: 2

Compression:

Stored size: 790 Bytes

Contents

module GovKit
  module CA
    module PostalCode
      module Strategy
        # elections.ca is a reliable source, but it does not return electoral
        # districts for postal codes that contain multiple electoral districts.
        # @see https://github.com/danielharan/postal_code_to_edid_webservice
        class ElectionsCa < Base
          base_uri 'elections.ca'

        private

          def electoral_districts!
            [ response.headers['location'][/&ED=(\d{5})&/, 1] ]
          end

          def valid?
            !!response.headers['location']
          end

          def response
            @response ||= self.class.head "/scripts/pss/FindED.aspx?PC=#{@postal_code}"
          end
        end

        StrategySet.register ElectionsCa
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
govkit-ca-0.0.2 lib/gov_kit-ca/postal_code/strategy/elections-ca.rb
govkit-ca-0.0.1 lib/gov_kit-ca/postal_code/strategy/elections-ca.rb