Class RDig::Application
In: lib/rdig.rb
Parent: Object

Methods

Constants

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."], ]

Public Instance methods

Return a list of the command line options supported by the program.

[Source]

     # File lib/rdig.rb, line 198
198:     def command_line_options
199:       OPTIONS.collect { |lst| lst[0..-2] }
200:     end

Do the option defined by opt and value.

[Source]

     # File lib/rdig.rb, line 203
203:     def do_option(opt, value)
204:       case opt
205:       when '--help'
206:         help
207:         exit
208:       when '--config'
209:         options.config_file = value
210:       when '--query'
211:         options.query = value
212:       when '--version'
213:         puts "rdig, version #{RDIGVERSION}"
214:         exit
215:       else
216:         fail "Unknown option: #{opt}"
217:       end 
218:     end

Read and handle the command line options.

[Source]

     # File lib/rdig.rb, line 221
221:     def handle_options
222:       opts = GetoptLong.new(*command_line_options)
223:       opts.each { |opt, value| do_option(opt, value) }
224:     end

Display the rake command line help.

[Source]

     # File lib/rdig.rb, line 180
180:     def help
181:       usage
182:       puts
183:       puts "Options are ..."
184:       puts
185:       OPTIONS.sort.each do |long, short, mode, desc|
186:         if mode == GetoptLong::REQUIRED_ARGUMENT
187:           if desc =~ /\b([A-Z]{2,})\b/
188:             long = long + "=#{$1}"
189:           end
190:         end
191:         printf "  %-20s (%s)\n", long, short
192:         printf "      %s\n", desc
193:       end
194:     end

Load the configuration

[Source]

     # File lib/rdig.rb, line 227
227:     def load_configfile
228:       load File.expand_path(options.config_file)
229:     end

Application options from the command line

[Source]

     # File lib/rdig.rb, line 170
170:     def options
171:       @options ||= OpenStruct.new
172:     end

Run the rdig application.

[Source]

     # File lib/rdig.rb, line 232
232:     def run
233:       puts "RDig version #{RDIGVERSION}"
234:       handle_options
235:       begin
236:         load_configfile
237:       rescue
238:         puts $!.backtrace
239:         fail "No Configfile found!\n#{$!}"
240:         
241:       end    
242: 
243:       puts "using Ferret #{Ferret::VERSION}"
244: 
245:       if options.query
246:         # query the index
247:         puts "executing query >#{options.query}<"
248:         results = RDig.searcher.search(options.query)
249:         puts "total results: #{results[:hitcount]}"
250:         results[:list].each { |result|
251:           puts "\#{result[:url]}\n\#{result[:title]}\n\#{result[:extract]}\n\n"
252:         }
253:       else
254:         # rebuild index
255:         @crawler = Crawler.new
256:         @crawler.run
257:       end
258:     end

Display the program usage line.

[Source]

     # File lib/rdig.rb, line 175
175:     def usage
176:       puts "rdig -c configfile {options}"
177:     end

[Validate]