| 
									
										
										
										
											2024-08-12 10:30:59 +01:00
										 |  |  | # typed: true # rubocop:todo Sorbet/StrictSigil | 
					
						
							| 
									
										
										
										
											2023-04-18 00:22:13 +01:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "version" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class URL | 
					
						
							|  |  |  |   attr_reader :specs, :using | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sig { params(url: String, specs: T::Hash[Symbol, T.untyped]).void } | 
					
						
							|  |  |  |   def initialize(url, specs = {}) | 
					
						
							|  |  |  |     @url = url.freeze | 
					
						
							|  |  |  |     @specs = specs.dup | 
					
						
							|  |  |  |     @using = @specs.delete(:using) | 
					
						
							|  |  |  |     @specs.freeze | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sig { returns(String) } | 
					
						
							|  |  |  |   def to_s | 
					
						
							|  |  |  |     @url | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sig { returns(T.class_of(AbstractDownloadStrategy)) } | 
					
						
							|  |  |  |   def download_strategy | 
					
						
							|  |  |  |     @download_strategy ||= DownloadStrategyDetector.detect(@url, @using) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sig { returns(Version) } | 
					
						
							|  |  |  |   def version | 
					
						
							|  |  |  |     @version ||= Version.detect(@url, **@specs) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |