Class: UsageMod::OpenURIInputPlugin

Inherits:
FilePlugin show all
Defined in:
lib/Usage.rb

Instance Attribute Summary

Attributes inherited from ArgumentParserPlugin

#value

Instance Method Summary collapse

Methods inherited from FilePlugin

#close

Methods inherited from ArgumentParserPlugin

#close

Constructor Details

#initialize(usage_ui, str) ⇒ OpenURIInputPlugin

Returns a new instance of OpenURIInputPlugin.



526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/Usage.rb', line 526

def initialize(usage_ui, str)
	$TRACE.debug 5, "trying to open uri '#{str}' for input"

	# see if it looks like a URI
	m = /^(\w+):\/\//.match(str)

	# if it matches and its not either http or ftp (which is all open-uri
	# does at this point
	if m && !(["http", "ftp"].include?(m[1].downcase)) then
		# tell the user
		raise OpenURIBadFormatError.new(str)
	end

	# if it starts with www. or ftp. then just pre-pend the transport protocol
	if m = /^(www|ftp)\./i.match(str) then
		if m[1].downcase == "www" then
			str = "http://" + str
		else
			str = "ftp://" + str
		end
	end
	
	# try opening it with open-uri
	begin
		@value = open(str)
	rescue Exception => e
		puts e.message
		raise IOInputError.new(str, e.message)
	end
end