Class: Softcover::Book::BookFile
- Inherits:
-
Struct
- Object
- Struct
- Softcover::Book::BookFile
- Defined in:
- lib/softcover/book.rb
Constant Summary collapse
- LAST_WRITE_HORIZON =
5
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ BookFile
constructor
A new instance of BookFile.
- #ready? ⇒ Boolean
- #to_json(opts = {}) ⇒ Object
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
#checksum ⇒ Object
Returns the value of attribute checksum.
24 25 26 |
# File 'lib/softcover/book.rb', line 24 def checksum @checksum end |
#path ⇒ Object
Returns the value of attribute 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
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 |