Class: SPath::Shortcut
- Inherits:
-
Object
- Object
- SPath::Shortcut
- Defined in:
- lib/spath.rb
Instance Attribute Summary collapse
-
#nickname ⇒ Object
Returns the value of attribute nickname.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
-
.[](data) ⇒ Object
Create instance from hash.
Instance Method Summary collapse
-
#initialize(nickname, path) ⇒ Shortcut
constructor
A new instance of Shortcut.
- #to_hash ⇒ Object
Constructor Details
#initialize(nickname, path) ⇒ Shortcut
Returns a new instance of Shortcut.
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.(path) raise ArgumentError, "path '#{path}' doesn't exist" \ unless File.exists? path @nickname = nickname.to_s.to_sym @path = path end |
Instance Attribute Details
#nickname ⇒ Object
Returns the value of attribute nickname.
62 63 64 |
# File 'lib/spath.rb', line 62 def nickname @nickname end |
#path ⇒ Object
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_hash ⇒ Object
78 79 80 |
# File 'lib/spath.rb', line 78 def to_hash { nickname: @nickname.to_s, path: @path } end |