class SPath::Shortcut

Attributes

nickname[RW]
path[RW]

Public Class Methods

[](data) click to toggle source

Create instance from hash

# File lib/spath.rb, line 83
def self.[](data)
  new(data[:nickname], data[:path])
end
new(nickname, path) click to toggle source
# File lib/spath.rb, line 64
def initialize(nickname, path)
  raise ArgumentError, "#{nickname} is not alphanumeric" \
    if nickname.to_s =~ /[^a-z0-9_]/i
  raise ArgumentError, "nickname is not a string" \
    unless nickname.respond_to? :to_s

  path = File.expand_path(path)
  raise ArgumentError, "path '#{path}' doesn't exist" \
    unless File.exists? path

  @nickname = nickname.to_s.to_sym
  @path = path
end

Public Instance Methods

to_hash() click to toggle source
# File lib/spath.rb, line 78
def to_hash
  { nickname: @nickname.to_s, path: @path }
end