Class: Archaeo::AssetList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
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.



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

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

Instance Method Details

#add(url, type:) ⇒ Object



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

def add(url, type:)
  return if url.nil? || url.empty?
  return if @urls_by_type[type].include?(url)

  @urls_by_type[type] << url
end

#allObject



51
52
53
# File 'lib/archaeo/asset_list.rb', line 51

def all
  @urls_by_type.values.flatten.uniq
end

#countsObject



71
72
73
# File 'lib/archaeo/asset_list.rb', line 71

def counts
  @urls_by_type.transform_values(&:size)
end

#cssObject



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

def css
  @urls_by_type[:css]
end

#each(&block) ⇒ Object



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

def each(&block)
  all.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/archaeo/asset_list.rb', line 59

def empty?
  all.empty?
end

#fontsObject



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

def fonts
  @urls_by_type[:font]
end

#imagesObject



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

def images
  @urls_by_type[:image]
end

#jsObject



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

def js
  @urls_by_type[:js]
end

#mediaObject



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

def media
  @urls_by_type[:media]
end

#sizeObject



55
56
57
# File 'lib/archaeo/asset_list.rb', line 55

def size
  all.size
end

#to_hObject



63
64
65
# File 'lib/archaeo/asset_list.rb', line 63

def to_h
  @urls_by_type.transform_values(&:dup)
end

#to_json(*args) ⇒ Object



67
68
69
# File 'lib/archaeo/asset_list.rb', line 67

def to_json(*args)
  to_h.to_json(*args)
end