Sha256: dbce43289e2f83c5e2d90c25fb2d9e00d78ec07fac87da9550b96edcbd210bf1

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module GovKit
  module CA
    module PostalCode
      module Strategy
        # cbc.ca ought to be a reliable source. It is unknown if its database
        # is kept up-to-date between elections, however.
        # @see https://github.com/danielharan/pc_scraper
        class CBCCa < Base
          base_uri 'www.cbc.ca'
          http_method :get
          path '/news/politics/canadavotes2011/myelection/postalcodes/index.php?pc=<%= @postal_code %>'

        private
          def electoral_districts!
            Yajl::Parser.parse(response.parsed_response).map{|x| self.class.rid_to_edid[x['rid'].to_i]}
          end

          def valid?
            response.code != 404
          end

          # cbc.ca uses an internal riding ID, which must be matched to a
          # canonical electoral district ID.
          # @return [Hash] a map of cbc.ca riding ID to electoral district ID
          def self.rid_to_edid
            @@yml ||= YAML.load_file(File.expand_path('../../../../data/rid_to_edid.yml', __FILE__))
          end
        end

        StrategySet.register CBCCa
      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/cbc_ca.rb