Class: Softcover::Book::BookFile
- Inherits:
-
Struct
- Object
- Struct
- Softcover::Book::BookFile
- Defined in:
- lib/softcover/book.rb
Constant Summary collapse
- LAST_WRITE_HORIZON =
0
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.
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
#checksum ⇒ Object
Returns the value of attribute checksum.
27 28 29 |
# File 'lib/softcover/book.rb', line 27 def checksum @checksum end |
#path ⇒ Object
Returns the value of attribute 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
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 |