Module: GovKit::CA::PostalCode::StrategySet
- Defined in:
- lib/gov_kit-ca/postal_code/strategy_set.rb
Overview
The set of postal code to electoral district strategies.
Class Method Summary collapse
-
.register(strategy) ⇒ Array<Strategy::Base>
Adds a strategy to the strategy set.
-
.run(postal_code) ⇒ Array<Fixnum>
Runs through the strategies in order of registration.
-
.strategies ⇒ Array<Strategy::Base>
Stores the strategy set.
Class Method Details
.register(strategy) ⇒ Array<Strategy::Base>
Adds a strategy to the strategy set.
15 16 17 |
# File 'lib/gov_kit-ca/postal_code/strategy_set.rb', line 15 def self.register(strategy) strategies << strategy unless strategies.include?(strategy) end |
.run(postal_code) ⇒ Array<Fixnum>
Runs through the strategies in order of registration. Returns the output of the first strategy to successfully determine electoral districts from a postal code.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gov_kit-ca/postal_code/strategy_set.rb', line 25 def self.run(postal_code) strategies.each do |strategy| begin electoral_districts = strategy.new(postal_code).electoral_districts return electoral_districts if electoral_districts rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError # Do nothing. Continue. end end raise ResourceNotFound end |
.strategies ⇒ Array<Strategy::Base>
Stores the strategy set.
8 9 10 |
# File 'lib/gov_kit-ca/postal_code/strategy_set.rb', line 8 def self.strategies @@strategies ||= [] end |