Class: Archaeo::ArchiveUrl
- Inherits:
-
Object
- Object
- Archaeo::ArchiveUrl
- Defined in:
- lib/archaeo/archive_url.rb
Overview
Model representing a Wayback Machine archive URL.
Encapsulates URL construction and parsing for archive.org URLs, supporting both normal and identity (raw) modes.
Constant Summary collapse
- BASE =
"https://web.archive.org/web"- TIMESTAMP_RE =
%r{web\.archive\.org/web/(\d{14})}
Instance Attribute Summary collapse
-
#original_url ⇒ Object
readonly
Returns the value of attribute original_url.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #identity? ⇒ Boolean
-
#initialize(original_url, timestamp:, identity: false) ⇒ ArchiveUrl
constructor
A new instance of ArchiveUrl.
- #to_s ⇒ Object
Constructor Details
#initialize(original_url, timestamp:, identity: false) ⇒ ArchiveUrl
Returns a new instance of ArchiveUrl.
15 16 17 18 19 |
# File 'lib/archaeo/archive_url.rb', line 15 def initialize(original_url, timestamp:, identity: false) @original_url = original_url.to_s @timestamp = Timestamp.coerce() @identity = identity end |
Instance Attribute Details
#original_url ⇒ Object (readonly)
Returns the value of attribute original_url.
13 14 15 |
# File 'lib/archaeo/archive_url.rb', line 13 def original_url @original_url end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
13 14 15 |
# File 'lib/archaeo/archive_url.rb', line 13 def @timestamp end |
Class Method Details
.parse(string) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/archaeo/archive_url.rb', line 21 def self.parse(string) match = string.match(TIMESTAMP_RE) unless match raise ArgumentError, "Not a valid archive URL: #{string}" end ts = Timestamp.parse(match[1]) identity = string.include?("#{match[1]}id_/") rest = extract_original_url(string, match[1], identity) new(rest, timestamp: ts, identity: identity) end |
Instance Method Details
#identity? ⇒ Boolean
35 36 37 |
# File 'lib/archaeo/archive_url.rb', line 35 def identity? @identity end |
#to_s ⇒ Object
39 40 41 42 |
# File 'lib/archaeo/archive_url.rb', line 39 def to_s suffix = identity? ? "id_" : "" "#{BASE}/#{@timestamp}#{suffix}/#{@original_url}" end |