Sha256: 45877555e132f08b83d336da488fe0e9c031ee455bf332ef1bc2fdc8b5ad1268

Contents?: true

Size: 848 Bytes

Versions: 1

Compression:

Stored size: 848 Bytes

Contents

module GovKit
  module CA
    module PostalCode
      module Strategy
        # digital-copyright.ca often returns more or fewer electoral districts
        # than others. It says it uses makethechange.ca, but makethechange.ca
        # returns different results for, e.g., K0A1K0.
        class DigitalCopyrightCa < Base
          base_uri 'www.digital-copyright.ca'
          http_method :get
          path '/edid/postal?postalcode=<%= @postal_code %>'

        private

          def electoral_districts!
            Nokogiri::HTML(response.parsed_response, nil, 'utf-8').css('.node .content a').map{|a| a[:href][/\d+\z/]}
          end

          def valid?
            !response.parsed_response.match /\b(invalid postal code|not found)\b/
          end
        end

        StrategySet.register DigitalCopyrightCa
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
govkit-ca-0.0.4 lib/gov_kit-ca/postal_code/strategy/digital-copyright_ca.rb