Class: Metalink4FileUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/metalink4.rb

Overview

Describes the download urls of files listed in the Metalink 4 file

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#locationObject

Returns the value of attribute location.



55
56
57
# File 'lib/metalink4.rb', line 55

def location
  @location
end

#priorityObject

Returns the value of attribute priority.



55
56
57
# File 'lib/metalink4.rb', line 55

def priority
  @priority
end

#urlObject

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(builder_metalink_file, local_path)
  begin
    if MIME::Types.type_for(local_path.to_s).first == MIME::Types.type_for( self.url.path ).first
      builder_metalink_file.url(
        self.url.to_s, {
          location: self.location,
          priority: self.priority || 1,
          }.delete_if{ |k, v| v.nil? }
        )
    else
      builder_metalink_file.metaurl(
        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