Class: KindleMailFileDatastore
- Inherits:
-
Object
- Object
- KindleMailFileDatastore
- Defined in:
- lib/KindleMailFileDatastore.rb
Instance Method Summary collapse
- #add_entry(kindle_addr, filename) ⇒ Object
- #clear_history ⇒ Object
- #file_exists?(kindle_addr, filename) ⇒ Boolean
- #load_store ⇒ Object
- #print_history ⇒ Object
Instance Method Details
#add_entry(kindle_addr, filename) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/KindleMailFileDatastore.rb', line 26 def add_entry(kindle_addr,filename) load_store @db[kindle_addr] = {} if(@db[kindle_addr].nil?) @db[kindle_addr][filename] = Time.now data = Marshal.dump(@db) file = File.new(FILE_STORE, "w") file.write data file.close end |
#clear_history ⇒ Object
51 52 53 |
# File 'lib/KindleMailFileDatastore.rb', line 51 def clear_history FileUtils.rm(FILE_STORE) if File.exist?(FILE_STORE) end |
#file_exists?(kindle_addr, filename) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/KindleMailFileDatastore.rb', line 13 def file_exists?(kindle_addr, filename) load_store if(@db.key?kindle_addr == false) return false elsif(@db[kindle_addr].nil?) return false elsif(@db[kindle_addr].key?filename) puts "This file was sent to #{kindle_addr} on #{@db[kindle_addr][filename]}" return true end return false end |
#load_store ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/KindleMailFileDatastore.rb', line 4 def load_store if(File.exist?(FILE_STORE)) data = IO.read(FILE_STORE) @db = Marshal.load(data) else @db = {} end end |
#print_history ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/KindleMailFileDatastore.rb', line 36 def print_history load_store puts "*** History of files sent using kindlemail (use the -d option to clear the history) ***\n\n" if !@db.empty? @db.each { |email, val| puts email puts "-"*100 val.each { |filename,sentdate| print " => " + filename + " was sent on " + sentdate.strftime("%a %d %h %H:%M:%S") + "\n" } puts "-"*100 } else puts "There are no items in the history" end end |