Class: Archaeo::Snapshot
- Inherits:
-
Object
- Object
- Archaeo::Snapshot
- Defined in:
- lib/archaeo/snapshot.rb
Overview
A single CDX Server API record representing an archived document.
Maps the seven standard CDX fields and provides the computed archive URL via the ArchiveUrl model.
Constant Summary collapse
- FIELDS =
%i[urlkey timestamp original_url mimetype status_code digest length].freeze
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #archive_url ⇒ Object
- #hash ⇒ Object
-
#initialize(urlkey:, timestamp:, original_url:, mimetype: nil, status_code: nil, digest: nil, length: nil) ⇒ Snapshot
constructor
A new instance of Snapshot.
Constructor Details
#initialize(urlkey:, timestamp:, original_url:, mimetype: nil, status_code: nil, digest: nil, length: nil) ⇒ Snapshot
Returns a new instance of Snapshot.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/archaeo/snapshot.rb', line 14 def initialize(urlkey:, timestamp:, original_url:, mimetype: nil, status_code: nil, digest: nil, length: nil) @urlkey = urlkey.to_s @timestamp = Timestamp.coerce() @original_url = original_url.to_s @mimetype = mimetype.to_s @status_code = status_code.to_i @digest = digest.to_s @length = length.to_i end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
30 31 32 33 |
# File 'lib/archaeo/snapshot.rb', line 30 def ==(other) other.is_a?(self.class) && FIELDS.all? { |f| send(f) == other.send(f) } end |
#archive_url ⇒ Object
26 27 28 |
# File 'lib/archaeo/snapshot.rb', line 26 def archive_url ArchiveUrl.new(original_url, timestamp: @timestamp).to_s end |
#hash ⇒ Object
36 37 38 |
# File 'lib/archaeo/snapshot.rb', line 36 def hash FIELDS.map { |f| send(f) }.hash end |