Class: SPath::Shortcut

Inherits:
Object
  • Object
show all
Defined in:
lib/spath.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nickname, path) ⇒ Shortcut

Returns a new instance of Shortcut.

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
# 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

Instance Attribute Details

#nicknameObject

Returns the value of attribute nickname.



62
63
64
# File 'lib/spath.rb', line 62

def nickname
  @nickname
end

#pathObject

Returns the value of attribute path.



62
63
64
# File 'lib/spath.rb', line 62

def path
  @path
end

Class Method Details

.[](data) ⇒ Object

Create instance from hash



83
84
85
# File 'lib/spath.rb', line 83

def self.[](data)
  new(data[:nickname], data[:path])
end

Instance Method Details

#to_hashObject



78
79
80
# File 'lib/spath.rb', line 78

def to_hash
  { nickname: @nickname.to_s, path: @path }
end