Class: Archaeo::Snapshot

Inherits:
Object
  • Object
show all
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

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(timestamp)
  @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_urlObject



28
29
30
# File 'lib/archaeo/snapshot.rb', line 28

def archive_url
  ArchiveUrl.new(original_url, timestamp: @timestamp).to_s
end

#blocked?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/archaeo/snapshot.rb', line 32

def blocked?
  @status_code == BLOCKED_STATUS
end

#hashObject



46
47
48
# File 'lib/archaeo/snapshot.rb', line 46

def hash
  to_a.hash
end

#to_aObject



36
37
38
39
# File 'lib/archaeo/snapshot.rb', line 36

def to_a
  [@urlkey, @timestamp, @original_url, @mimetype,
   @status_code, @digest, @length]
end