Module: Divan::Utils

Defined in:
lib/divan/utils.rb

Class Method Summary collapse

Class Method Details

.formatted_path(path = nil, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/divan/utils.rb', line 14

def self.formatted_path(path = nil, opts = {})
  if opts.empty?
    CGI.escape path.to_s
  else
    formatted_opts = opts.map{|k,v| "#{CGI.escape k.to_s}=#{URI.encode v.to_s}"}.join('&')
    "#{path.to_s}?#{formatted_opts}"
  end
end

.parse_time(string) ⇒ Object



9
10
11
12
# File 'lib/divan/utils.rb', line 9

def self.parse_time(string)
  parsed_time     = Date._parse string
  Time.gm *[:year, :mon, :mday, :hour, :min, :sec].collect{ |k| parsed_time[k] }
end

.uuidObject



3
4
5
6
7
# File 'lib/divan/utils.rb', line 3

def self.uuid
  values = [ rand(0x0010000), rand(0x0010000), rand(0x0010000), rand(0x0010000),
             rand(0x0010000), rand(0x1000000), rand(0x1000000) ]
  "%04x%04x%04x%04x%04x%06x%06x" % values
end