Sha256: 2b05a99479276bb8ebf0ba994ca5af098e0c230c135fac2917987d39ccec0836

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 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)
          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.1 lib/gov_kit-ca/postal_code/strategy/base.rb