Sha256: 7b4536680c1a8e8192e37a5462ad18a44f474ef73141669229c29222c2405ea7

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module GovKit
  module CA
    module PostalCode
      module Strategy
        # Abstract class for implementing postal code to electoral district
        # strategies.
        #
        # The following methods must be implemented in sub-classes:
        #
        # * `electoral_districts!`
        class Base
          include HTTParty
          follow_redirects false
          headers 'User-Agent' => 'GovKit-CA +http://govkit.org'

          # Creates a new postal code to electoral district strategy.
          # @param [String] postal_code a postal code
          def initialize(postal_code)
            @postal_code = postal_code
          end

          # Returns the electoral districts within a postal code.
          # @return [Array<Fixnum>] the electoral districts within the postal code
          def electoral_districts
            valid? && electoral_districts!.map(&:to_i).sort
          end

        private

          # Returns the electoral districts within a postal code, without
          # passing validation first.
          # @return [Array<Fixnum>] the electoral districts within the postal code
          def electoral_districts!
            raise NotImplementedError
          end

          # @return [Boolean] whether the electoral districts can be determined
          def valid?
            true
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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