Class: RDig::Application
- Inherits:
-
Object
- Object
- RDig::Application
- Defined in:
- lib/rdig.rb
Constant Summary collapse
- OPTIONS =
[ ['--config', '-c', GetoptLong::REQUIRED_ARGUMENT, "Read aplication configuration from CONFIG."], ['--help', '-h', GetoptLong::NO_ARGUMENT, "Display this help message."], ['--query', '-q', GetoptLong::REQUIRED_ARGUMENT, "Execute QUERY."], ['--version', '-v', GetoptLong::NO_ARGUMENT, "Display the program version."], ]
Instance Method Summary collapse
-
#command_line_options ⇒ Object
Return a list of the command line options supported by the program.
-
#do_option(opt, value) ⇒ Object
Do the option defined by
opt
andvalue
. -
#handle_options ⇒ Object
Read and handle the command line options.
-
#help ⇒ Object
Display the rake command line help.
-
#load_configfile ⇒ Object
Load the configuration.
-
#options ⇒ Object
Application options from the command line.
-
#run ⇒ Object
Run the
rdig
application. -
#usage ⇒ Object
Display the program usage line.
Instance Method Details
#command_line_options ⇒ Object
Return a list of the command line options supported by the program.
228 229 230 |
# File 'lib/rdig.rb', line 228 def OPTIONS.collect { |lst| lst[0..-2] } end |
#do_option(opt, value) ⇒ Object
Do the option defined by opt
and value
.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/rdig.rb', line 233 def do_option(opt, value) case opt when '--help' help exit when '--config' .config_file = value when '--query' .query = value when '--version' exit else fail "Unknown option: #{opt}" end end |
#handle_options ⇒ Object
Read and handle the command line options.
250 251 252 253 |
# File 'lib/rdig.rb', line 250 def opts = GetoptLong.new(*) opts.each { |opt, value| do_option(opt, value) } end |
#help ⇒ Object
Display the rake command line help.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/rdig.rb', line 210 def help usage puts puts "Options are ..." puts OPTIONS.sort.each do |long, short, mode, desc| if mode == GetoptLong::REQUIRED_ARGUMENT if desc =~ /\b([A-Z]{2,})\b/ long = long + "=#{$1}" end end printf " %-20s (%s)\n", long, short printf " %s\n", desc end end |
#load_configfile ⇒ Object
Load the configuration
256 257 258 |
# File 'lib/rdig.rb', line 256 def load_configfile load File.(.config_file) end |
#options ⇒ Object
Application options from the command line
200 201 202 |
# File 'lib/rdig.rb', line 200 def @options ||= OpenStruct.new end |
#run ⇒ Object
Run the rdig
application.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/rdig.rb', line 261 def run puts "RDig version #{RDIGVERSION}" begin load_configfile rescue puts $!.backtrace fail "No Configfile found!\n#{$!}" end puts "using Ferret #{Ferret::VERSION}" if .query # query the index puts "executing query >#{.query}<" results = RDig.searcher.search(.query) puts "total results: #{results[:hitcount]}" results[:list].each { |result| puts <<-EOF #{result[:url]} #{result[:title]} #{result[:extract]} EOF } else # rebuild index @crawler = Crawler.new @crawler.run end end |
#usage ⇒ Object
Display the program usage line.
205 206 207 |
# File 'lib/rdig.rb', line 205 def usage puts "rdig -c configfile {options}" end |