Sha256: d84af1a3e7a3e1404376865ecf8110d2cbba42d9e0b4cb7686b797625b58529d

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

require "takuhai_status/version"
require "takuhai_status/japanpost"
require "takuhai_status/kuronekoyamato"
require "takuhai_status/sagawa"
require "takuhai_status/tmg_cargo"
require "takuhai_status/ups"
require "takuhai_status/fedex"

module TakuhaiStatus
	class NotFound < StandardError; end
	class NotMyKey < StandardError; end
	class Multiple < StandardError
		attr_reader :services
		def initialize(msg, services)
			super(msg)
			@services = services
		end
	end

	def self.scan(key)
		services = []
		[].tap{|threads|
			[Sagawa, JapanPost, KuronekoYamato, TMGCargo, UPS, FedEx].each do |service|
				threads.push(Thread.new{service.new(key)})
			end
		}.each{|thread|
			begin
				services.push(thread.value)
			rescue NotMyKey
			end
		}

		case services.size
		when 0
			raise NotFound
		when 1
			return services.first
		else
			services.delete_if{|service| service.finish?}
			case services.size
			when 0
				raise NotFound
			when 1
				return services.first
			else
				raise Multiple.new('some services found', services)
			end
		end
	end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
takuhai_status-1.6.0 lib/takuhai_status.rb
takuhai_status-1.5.5 lib/takuhai_status.rb
takuhai_status-1.5.4 lib/takuhai_status.rb
takuhai_status-1.5.3 lib/takuhai_status.rb
takuhai_status-1.5.2 lib/takuhai_status.rb
takuhai_status-1.5.1 lib/takuhai_status.rb
takuhai_status-1.5.0 lib/takuhai_status.rb