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
-
.dir_url(project, path = "") ⇒ Object
Directory page URL; path is the full path relative to the project root ("" = root).
- .encode_path(path) ⇒ Object
-
.encode_segment(name) ⇒ Object
Percent-encode a single path segment, byte-wise (keeps UTF-8 safe; space -> %20).
-
.file_url(project, full_path) ⇒ Object
Direct file download URL (redirects to a mirror).
Class Method Details
.dir_url(project, path = "") ⇒ Object
Directory page URL; path is the full path relative to the project root ("" = root).
96 97 98 99 |
# File 'lib/sfdown.rb', line 96 def dir_url(project, path = "") suffix = path.empty? ? "" : "#{encode_path(path)}/" "#{BASE}/projects/#{encode_segment(project)}/files/#{suffix}" end |
.encode_path(path) ⇒ Object
91 92 93 |
# File 'lib/sfdown.rb', line 91 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).
87 88 89 |
# File 'lib/sfdown.rb', line 87 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).
102 103 104 |
# File 'lib/sfdown.rb', line 102 def file_url(project, full_path) "#{DOWNLOADS}/project/#{encode_segment(project)}/#{encode_path(full_path)}" end |