module Gistribute

Public Class Methods

decode(filename) click to toggle source

Decodes the filename from the Gist into a usable path

# File lib/gistribute.rb, line 29
def decode(filename)
  filename.gsub(/[~|]/, "|" => "/", "~" => Dir.home)
end
encode(filename) click to toggle source

Encodes a file path for use in the Gist filename

# File lib/gistribute.rb, line 24
def encode(filename)
  filename.sub(/^#{Dir.home}/, "~").gsub("/", "|")
end
parse_id(str) click to toggle source

The user may enter either the full URL or just the ID, this function will parse it out of the input.

# File lib/gistribute.rb, line 19
def parse_id(str)
  str[%r{(^|/)([[:xdigit:]]+)}, 2]
end