Class: WebArchive::Completer
- Inherits:
-
Object
- Object
- WebArchive::Completer
- Defined in:
- lib/webarchive.rb
Overview
completer for URLs
Instance Method Summary collapse
- #append_to_history(str) ⇒ void
-
#initialize(history_file) ⇒ Completer
constructor
A new instance of Completer.
- #reload! ⇒ void
- #to_proc ⇒ Proc
- #update! ⇒ void
Constructor Details
#initialize(history_file) ⇒ Completer
Returns a new instance of Completer.
280 281 282 283 284 |
# File 'lib/webarchive.rb', line 280 def initialize(history_file) @file = history_file @trie = Trie.new reload! end |
Instance Method Details
#append_to_history(str) ⇒ void
This method returns an undefined value.
313 314 315 316 317 |
# File 'lib/webarchive.rb', line 313 def append_to_history(str) File.open(@file, mode: 'a', encoding: 'utf-8') do |f| f.puts str end end |
#reload! ⇒ void
This method returns an undefined value.
292 293 294 295 296 297 298 299 300 301 |
# File 'lib/webarchive.rb', line 292 def reload! if File.exist? @file File.open(@file, encoding: 'utf-8').each_line do |x| @trie.add x.strip end else File.new(@file, 'w', encoding: 'utf-8').flush end @lastupdate = Time.now end |
#to_proc ⇒ Proc
304 305 306 307 308 309 |
# File 'lib/webarchive.rb', line 304 def to_proc proc do |s| update! @trie.children(s) end end |
#update! ⇒ void
This method returns an undefined value.
287 288 289 |
# File 'lib/webarchive.rb', line 287 def update! reload! if File.stat(@file).mtime > @lastupdate end |