Class: Softcover::Book::BookFile

Inherits:
Struct
  • Object
show all
Defined in:
lib/softcover/book.rb

Constant Summary collapse

LAST_WRITE_HORIZON =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ BookFile

Returns a new instance of BookFile.



28
29
30
31
32
# File 'lib/softcover/book.rb', line 28

def initialize(*args)
  super
  @checksum = Digest::MD5.file(path).hexdigest
  (@@lookup ||= {})[path] = self
end

Instance Attribute Details

#checksumObject

Returns the value of attribute checksum.



27
28
29
# File 'lib/softcover/book.rb', line 27

def checksum
  @checksum
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



24
25
26
# File 'lib/softcover/book.rb', line 24

def path
  @path
end

Class Method Details

.find(path) ⇒ Object



43
44
45
# File 'lib/softcover/book.rb', line 43

def self.find(path)
  @@lookup[path]
end

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/softcover/book.rb', line 34

def ready?
  return true if Softcover::test?
  File::ctime(path).to_i < Time.now.to_i - LAST_WRITE_HORIZON
end

#to_json(opts = {}) ⇒ Object



39
40
41
# File 'lib/softcover/book.rb', line 39

def to_json(opts={})
  { path: path, checksum: @checksum }.to_json
end