Class: Softcover::Book::BookFile

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

Constant Summary collapse

LAST_WRITE_HORIZON =
5

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ BookFile

Returns a new instance of BookFile.



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

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

Instance Attribute Details

#checksumObject

Returns the value of attribute checksum.



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

def checksum
  @checksum
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



21
22
23
# File 'lib/softcover/book.rb', line 21

def path
  @path
end

Class Method Details

.find(path) ⇒ Object



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

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

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/softcover/book.rb', line 31

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

#to_json(opts = {}) ⇒ Object



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

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