Class: Anyicon::Collection
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
-
#collections ⇒ Hash
Retrieves the configured collections from Anyicon.
-
#download_all ⇒ void
Downloads all icons in the collection and saves them to the local file system.
-
#initialize(collection) ⇒ Collection
constructor
Initializes a new Collection instance for the specified collection.
-
#list ⇒ Array<Hash>
Lists all icons in the collection by fetching the directory contents from the repository.
Methods inherited from Common
Constructor Details
#initialize(collection) ⇒ Collection
Initializes a new Collection instance for the specified collection.
24 25 26 27 |
# File 'lib/anyicon/collections.rb', line 24 def initialize(collection) super() @collection = collection end |
Instance Method Details
#collections ⇒ Hash
Retrieves the configured collections from Anyicon.
57 58 59 |
# File 'lib/anyicon/collections.rb', line 57 def collections @collections ||= Anyicon.configuration.collections end |
#download_all ⇒ void
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 |
#list ⇒ Array<Hash>
Lists all icons in the collection by fetching the directory contents from the repository.
32 33 34 35 |
# File 'lib/anyicon/collections.rb', line 32 def list response = fetch(collection_url) JSON.parse(response&.body || '{}') end |