Class: Archaeo::AssetList

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

Overview

Categorized collection of asset URLs extracted from an archived page.

Assets are grouped by type (css, js, image, font, media) for convenient access during bulk download or local archiving.

Constant Summary collapse

CATEGORIES =
%i[css js image font media].freeze

Instance Method Summary collapse

Constructor Details

#initializeAssetList

Returns a new instance of AssetList.



11
12
13
14
# File 'lib/archaeo/asset_list.rb', line 11

def initialize
  @urls_by_type = {}
  CATEGORIES.each { |c| @urls_by_type[c] = [] }
end

Instance Method Details

#add(url, type:) ⇒ Object



16
17
18
# File 'lib/archaeo/asset_list.rb', line 16

def add(url, type:)
  @urls_by_type[type] << url unless url.nil? || url.empty?
end

#allObject



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

def all
  @urls_by_type.values.flatten.uniq
end

#cssObject



20
21
22
# File 'lib/archaeo/asset_list.rb', line 20

def css
  @urls_by_type[:css]
end

#empty?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/archaeo/asset_list.rb', line 48

def empty?
  all.empty?
end

#fontsObject



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

def fonts
  @urls_by_type[:font]
end

#imagesObject



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

def images
  @urls_by_type[:image]
end

#jsObject



24
25
26
# File 'lib/archaeo/asset_list.rb', line 24

def js
  @urls_by_type[:js]
end

#mediaObject



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

def media
  @urls_by_type[:media]
end

#sizeObject



44
45
46
# File 'lib/archaeo/asset_list.rb', line 44

def size
  all.size
end