Module: Sfdown::Sf

Defined in:
lib/sfdown.rb

Overview

SourceForge URL templates (see DOC.md).

Constant Summary collapse

BASE =
"https://sourceforge.net"
DOWNLOADS =
"https://downloads.sourceforge.net"

Class Method Summary collapse

Class Method Details

.dir_url(project, path = "") ⇒ Object

Directory page URL; path is the full path relative to the project root ("" = root).



103
104
105
106
# File 'lib/sfdown.rb', line 103

def dir_url(project, path = "")
  suffix = path.empty? ? "" : "#{encode_path(path)}/"
  "#{BASE}/projects/#{encode_segment(project)}/files/#{suffix}"
end

.encode_path(path) ⇒ Object



98
99
100
# File 'lib/sfdown.rb', line 98

def encode_path(path)
  path.split("/").map { |s| encode_segment(s) }.join("/")
end

.encode_segment(name) ⇒ Object

Percent-encode a single path segment, byte-wise (keeps UTF-8 safe; space -> %20).



94
95
96
# File 'lib/sfdown.rb', line 94

def encode_segment(name)
  name.b.gsub(%r{[^A-Za-z0-9\-_.~]}n) { |c| format("%%%02X", c.ord) }
end

.file_url(project, full_path) ⇒ Object

Direct file download URL (redirects to a mirror).



109
110
111
# File 'lib/sfdown.rb', line 109

def file_url(project, full_path)
  "#{DOWNLOADS}/project/#{encode_segment(project)}/#{encode_path(full_path)}"
end