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
- BLOCKED_STATUS =
-1
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #archive_url ⇒ Object
- #blocked? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(urlkey:, timestamp:, original_url:, mimetype: nil, status_code: nil, digest: nil, length: nil) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #to_a ⇒ Object
Constructor Details
#initialize(urlkey:, timestamp:, original_url:, mimetype: nil, status_code: nil, digest: nil, length: nil) ⇒ Snapshot
Returns a new instance of Snapshot.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/archaeo/snapshot.rb', line 16 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?
41 42 43 |
# File 'lib/archaeo/snapshot.rb', line 41 def ==(other) other.is_a?(self.class) && to_a == other.to_a end |
#archive_url ⇒ Object
28 29 30 |
# File 'lib/archaeo/snapshot.rb', line 28 def archive_url ArchiveUrl.new(original_url, timestamp: @timestamp).to_s end |
#blocked? ⇒ Boolean
32 33 34 |
# File 'lib/archaeo/snapshot.rb', line 32 def blocked? @status_code == BLOCKED_STATUS end |
#hash ⇒ Object
46 47 48 |
# File 'lib/archaeo/snapshot.rb', line 46 def hash to_a.hash end |
#to_a ⇒ Object
36 37 38 39 |
# File 'lib/archaeo/snapshot.rb', line 36 def to_a [@urlkey, @timestamp, @original_url, @mimetype, @status_code, @digest, @length] end |