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?



57
58
59
# File 'lib/archaeo/snapshot.rb', line 57

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



62
63
64
# File 'lib/archaeo/snapshot.rb', line 62

def hash
  to_a.hash
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  @status_code == 200
end

#to_aObject



40
41
42
43
# File 'lib/archaeo/snapshot.rb', line 40

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

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/archaeo/snapshot.rb', line 45

def to_h
  {
    urlkey: @urlkey,
    timestamp: @timestamp,
    original_url: @original_url,
    mimetype: @mimetype,
    status_code: @status_code,
    digest: @digest,
    length: @length,
  }
end