Class: Markify::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/markify/database.rb

Overview

Copyright Daniel Meißner <[email protected]>, 2013

This file is part of Markify.

Markify is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Markify is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Markify. If not, see <www.gnu.org/licenses/>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Database

Returns a new instance of Database.



25
26
27
28
# File 'lib/markify/database.rb', line 25

def initialize(path = nil)
  @file_path = path || Pathname(ENV['HOME'] + '/markify/hashes.txt')
  @checksums = read_checksum_file
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



23
24
25
# File 'lib/markify/database.rb', line 23

def file_path
  @file_path
end

Instance Method Details

#check_for_new_marks(marks) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/markify/database.rb', line 30

def check_for_new_marks(marks)
  new_marks = marks.clone

  read_checksum_file.each do |line|
    marks.each do |mark|
      if mark.hash.match(line)
        new_marks.delete(mark)
      end
    end
  end

  new_marks
end

#checksumsObject



50
51
52
53
54
55
56
57
58
# File 'lib/markify/database.rb', line 50

def checksums
  checksums = read_checksum_file

  checksums.each do |checksum|
    if checksum.match(/#/)
      checksums.delete(checksum)
    end
  end
end

#write_checksum(checksum) ⇒ Object



44
45
46
47
48
# File 'lib/markify/database.rb', line 44

def write_checksum(checksum)
  File.open(@file_path, 'a+') do |file|
    file.puts checksum
  end
end