Class: Anyicon::Collection

Inherits:
Common
  • Object
show all
Defined in:
lib/anyicon/collections.rb

Overview

The Collection class is responsible for managing icon collections from various repositories. It provides functionality to list and download all icons from a specified collection.

Example usage:

collection = Anyicon::Collection.new(:fontawesome_regular)
collection.list        # Lists all icons in the collection
collection.download_all # Downloads all icons in the collection

The class interacts with the configured collections in Anyicon::Configuration to determine the repository, path, and branch for each collection.

Instance Method Summary collapse

Methods inherited from Common

#fetch

Constructor Details

#initialize(collection) ⇒ Collection

Initializes a new Collection instance for the specified collection.

Parameters:

  • collection (Symbol)

    the name of the icon collection



24
25
26
27
# File 'lib/anyicon/collections.rb', line 24

def initialize(collection)
  super()
  @collection = collection
end

Instance Method Details

#collectionsHash

Retrieves the configured collections from Anyicon.

Returns:

  • (Hash)

    the configured collections



57
58
59
# File 'lib/anyicon/collections.rb', line 57

def collections
  @collections ||= Anyicon.configuration.collections
end

#download_allvoid

This method returns an undefined value.

Downloads all icons in the collection and saves them to the local file system.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/anyicon/collections.rb', line 40

def download_all
  if list.empty?
    puts 'No icons available.'
    return
  end

  count = 0
  list.each do |icon|
    count += 1
    download(icon)
  end
  puts "#{@collection}: #{count} downloads."
end

#listArray<Hash>

Lists all icons in the collection by fetching the directory contents from the repository.

Returns:

  • (Array<Hash>)

    a list of icons with their metadata



32
33
34
35
# File 'lib/anyicon/collections.rb', line 32

def list
  response = fetch(collection_url)
  JSON.parse(response&.body || '{}')
end