class CommandLineArgumentParser
Constants
- DOMAIN_CRAWLER
- WEB_CRAWLER
Attributes
crawl_depth[R]
crawl_type[R]
page_limit[R]
url_file[R]
Public Class Methods
new()
click to toggle source
# File lib/by_crawler/command_line_argument_parser.rb, line 10 def initialize unless ARGV.length >= 1 display_usage exit end @opts = GetoptLong.new( ["--crawl", "-c", GetoptLong::REQUIRED_ARGUMENT], ["--crawl-depth", "-d", GetoptLong::OPTIONAL_ARGUMENT], ["--page-limit", "-p", GetoptLong::OPTIONAL_ARGUMENT], ["--url-file", "-f", GetoptLong::OPTIONAL_ARGUMENT] ) @crawl_depth = 3 @crawl_type = "data.txt" @page_limit = 100 @url_file = 'urls.txt' end
Public Instance Methods
display_usage()
click to toggle source
# File lib/by_crawler/command_line_argument_parser.rb, line 28 def display_usage p "simple usage:" p "ruby search-engine-main.rb -c web -d 3 -p 100 -f 'urls.txt'" p "-c must be either 'web' or 'domain', will default to 'web' is your type garbage" end
ensure_crawl_type_correct(value)
click to toggle source
# File lib/by_crawler/command_line_argument_parser.rb, line 49 def ensure_crawl_type_correct(value) if value != WEB_CRAWLER && value != DOMAIN_CRAWLER @crawl_type = WEB_CRAWLER else @crawl_type = value end end
parse_arguments()
click to toggle source
# File lib/by_crawler/command_line_argument_parser.rb, line 34 def parse_arguments @opts.each do |opt, arg| case opt when '--crawl' ensure_crawl_type_correct(arg) when '--crawl-depth' @crawl_depth = arg when '--page-limit' @page_limit = arg when '--url-file' @url_file = arg end end end