Class: Archaeo::SaveResult

Inherits:
Object
  • Object
show all
Defined in:
lib/archaeo/save_result.rb

Overview

Model representing the outcome of a SavePageNow request.

Contains the resulting archive URL, timestamp, and whether the page was already cached in the archive.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, archive_url:, timestamp:, cached:) ⇒ SaveResult

Returns a new instance of SaveResult.



11
12
13
14
15
16
# File 'lib/archaeo/save_result.rb', line 11

def initialize(url:, archive_url:, timestamp:, cached:)
  @url = url
  @archive_url = archive_url
  @timestamp = timestamp ? Timestamp.coerce(timestamp) : nil
  @cached = cached
end

Instance Attribute Details

#archive_urlObject (readonly)

Returns the value of attribute archive_url.



9
10
11
# File 'lib/archaeo/save_result.rb', line 9

def archive_url
  @archive_url
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



9
10
11
# File 'lib/archaeo/save_result.rb', line 9

def timestamp
  @timestamp
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/archaeo/save_result.rb', line 9

def url
  @url
end

Instance Method Details

#as_jsonObject



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

def as_json(*)
  { url: @url, archive_url: @archive_url,
    timestamp: @timestamp.to_s, cached: @cached }
end

#cached?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/archaeo/save_result.rb', line 18

def cached?
  @cached
end

#inspectObject



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

def inspect
  "#<#{self.class.name} #{@url} cached=#{@cached}>"
end

#success?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/archaeo/save_result.rb', line 22

def success?
  !@archive_url.nil?
end

#to_hObject



26
27
28
29
# File 'lib/archaeo/save_result.rb', line 26

def to_h
  { url: @url, archive_url: @archive_url,
    timestamp: @timestamp, cached: @cached }
end

#to_sObject



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

def to_s
  label = @cached ? "Cached" : "Saved"
  "#{label}: #{@archive_url}"
end