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



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

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



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

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

#to_hObject



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

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

#to_sObject



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

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