Class: Metalink4FileUrl
- Inherits:
-
Object
- Object
- Metalink4FileUrl
- Defined in:
- lib/metalink4.rb
Overview
Describes the download urls of files listed in the Metalink 4 file
Instance Attribute Summary collapse
-
#location ⇒ Object
Returns the value of attribute location.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Metalink4FileUrl
constructor
Options: url, location, priority.
-
#render(builder_metalink_file, local_path) ⇒ Object
Fragement call for builder.
Constructor Details
#initialize(opts = {}) ⇒ Metalink4FileUrl
Options: url, location, priority. if only a string it profided it must be the URL.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/metalink4.rb', line 61 def initialize(opts = {}) self.priority = 1 case opts when String self.url = opts when Hash opts = opts.inject({}){ |r, (k,v)| r[k.to_sym] = v; r } self.url = opts[:url] self.location = opts[:location] self.priority = opts[:priority] else raise "URL format %s" % opts.inspect end end |
Instance Attribute Details
#location ⇒ Object
Returns the value of attribute location.
55 56 57 |
# File 'lib/metalink4.rb', line 55 def location @location end |
#priority ⇒ Object
Returns the value of attribute priority.
55 56 57 |
# File 'lib/metalink4.rb', line 55 def priority @priority end |
#url ⇒ Object
Returns the value of attribute url.
55 56 57 |
# File 'lib/metalink4.rb', line 55 def url @url end |
Instance Method Details
#render(builder_metalink_file, local_path) ⇒ Object
Fragement call for builder. For internal use.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/metalink4.rb', line 103 def render(, local_path) begin if MIME::Types.type_for(local_path.to_s).first == MIME::Types.type_for( self.url.path ).first .url( self.url.to_s, { location: self.location, priority: self.priority || 1, }.delete_if{ |k, v| v.nil? } ) else .( self.url.to_s, { priority: self.priority || 1, mediatype: self.url.path =~ /\.torrent/ ? "torrent" : MIME::Types.type_for( self.url.path ).first.to_s }.delete_if{ |k, v| v.nil? } ) end rescue puts [local_path, self.url] throw [local_path, self.url] end end |