Class: Hackmac::URLDownload
- Inherits:
-
Object
- Object
- Hackmac::URLDownload
- Includes:
- Tins::StringVersion
- Defined in:
- lib/hackmac/url_download.rb
Overview
A class that provides functionality for downloading assets from URLs with version tracking
The URLDownload class encapsulates the logic for managing downloadable assets by storing their name, version, and download URL. It provides methods to retrieve the asset data and metadata, making it suitable for use in systems that need to track and download software components from web sources.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name reader method provides access to the name attribute that was set during object initialization.
-
#version ⇒ String?
readonly
The version reader method provides access to the version attribute that was set during object initialization.
Instance Method Summary collapse
-
#download_asset ⇒ Array<String, String>?
The download_asset method retrieves binary data from a configured URL.
-
#initialize(name, version, url) ⇒ URLDownload
constructor
The initialize method sets up a URLDownload instance by storing the provided name, URL, and version information.
-
#inspect ⇒ String
The inspect method returns a string representation of the object that includes its class name and string value.
-
#to_s ⇒ String
The to_s method returns a string representation of the object by combining its name and version attributes into a single space-separated string.
Constructor Details
#initialize(name, version, url) ⇒ URLDownload
The initialize method sets up a URLDownload instance by storing the provided name, URL, and version information.
This method takes the necessary parameters to configure the download source and converts the version string into a Version object for later comparison.
30 31 32 33 34 |
# File 'lib/hackmac/url_download.rb', line 30 def initialize(name, version, url) @name = name @url = url @version = Version.new(version) end |
Instance Attribute Details
#name ⇒ String (readonly)
The name reader method provides access to the name attribute that was set during object initialization.
This method returns the value of the name instance variable, which typically represents the descriptive identifier or label associated with the object.
44 45 46 |
# File 'lib/hackmac/url_download.rb', line 44 def name @name end |
#version ⇒ String? (readonly)
The version reader method provides access to the version attribute that was set during object initialization.
This method returns the value of the version instance variable, which typically represents the semantic version number associated with the object’s current state or configuration.
54 55 56 |
# File 'lib/hackmac/url_download.rb', line 54 def version @version end |
Instance Method Details
#download_asset ⇒ Array<String, String>?
The download_asset method retrieves binary data from a configured URL
This method performs an HTTP GET request to the stored URL to download the associated asset file. It returns both the filename derived from the URL and the raw binary data content.
64 65 66 67 68 69 70 71 |
# File 'lib/hackmac/url_download.rb', line 64 def download_asset data = URI.open( @url, 'Accept' => 'application/octet-stream', &:read ) return File.basename(@url), data end |
#inspect ⇒ String
The inspect method returns a string representation of the object that includes its class name and string value
78 79 80 |
# File 'lib/hackmac/url_download.rb', line 78 def inspect "#<#{self.class}: #{to_s}>" end |
#to_s ⇒ String
The to_s method returns a string representation of the object by combining its name and version attributes into a single space-separated string.
88 89 90 |
# File 'lib/hackmac/url_download.rb', line 88 def to_s "#{name} #{version}" end |