mirror of
https://github.com/ticky/wayback-classic.git
synced 2026-06-11 23:57:20 -04:00
36 lines
917 B
Ruby
36 lines
917 B
Ruby
require 'erb'
|
|
|
|
def render(template, binding = {})
|
|
path = File.join(File.expand_path(File.dirname(__FILE__)), "../../templates/#{template}.erb")
|
|
erb = ERB.new(File.read(path))
|
|
erb.location = path
|
|
erb.result_with_hash(binding)
|
|
end
|
|
|
|
def uri(base = "", **kwargs)
|
|
URI(base).tap do |uri|
|
|
uri.query = URI.encode_www_form kwargs
|
|
end
|
|
end
|
|
|
|
def number_formatter(number)
|
|
number.to_s.gsub(/\B(?=(...)*\b)/, ',')
|
|
end
|
|
|
|
def filesize(size)
|
|
size = size.to_i
|
|
|
|
units = %w[B KiB MiB GiB TiB Pib EiB ZiB]
|
|
|
|
return '0.0 B' if size == 0
|
|
exp = (Math.log(size) / Math.log(1024)).to_i
|
|
exp += 1 if (size.to_f / 1024 ** exp >= 1024 - 0.05)
|
|
exp = units.size - 1 if exp > units.size - 1
|
|
|
|
'%.0f %s' % [size.to_f / 1024 ** exp, units[exp]]
|
|
end
|
|
|
|
def month_index_to_name(index)
|
|
["N/A", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][index]
|
|
end
|