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) ⇒ Object
-
#initialize(history_file) ⇒ Completer
constructor
A new instance of Completer.
- #reload ⇒ Object
- #to_proc ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(history_file) ⇒ Completer
Returns a new instance of Completer.
113 114 115 116 117 |
# File 'lib/webarchive.rb', line 113 def initialize(history_file) @file = File.(history_file) @trie = Trie.new self.reload end |
Instance Method Details
#append_to_history(str) ⇒ Object
141 142 143 144 145 |
# File 'lib/webarchive.rb', line 141 def append_to_history(str) File.open(@file, mode: 'a', encoding: 'utf-8') do |f| f.puts str end end |
#reload ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/webarchive.rb', line 123 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 ⇒ Object
134 135 136 137 138 139 |
# File 'lib/webarchive.rb', line 134 def to_proc proc do |s| self.update @trie.children(s) end end |
#update ⇒ Object
119 120 121 |
# File 'lib/webarchive.rb', line 119 def update self.reload if File.stat(@file).mtime > @lastupdate end |