Class: Noty::Snippet

Inherits:
Object
  • Object
show all
Defined in:
lib/noty/models/snippet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Snippet

Returns a new instance of Snippet.



8
9
10
11
# File 'lib/noty/models/snippet.rb', line 8

def initialize(path)
  @path = path
  @content = File.exist?(path) ? File.read(path) : ''
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/noty/models/snippet.rb', line 6

def content
  @content
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/noty/models/snippet.rb', line 6

def path
  @path
end

Instance Method Details

#copyObject



25
26
27
# File 'lib/noty/models/snippet.rb', line 25

def copy
  Helpers.copy content
end

#deleteObject



17
18
19
# File 'lib/noty/models/snippet.rb', line 17

def delete
  File.delete path
end

#editObject



29
30
31
# File 'lib/noty/models/snippet.rb', line 29

def edit
  Helpers.edit path
end

#openObject



21
22
23
# File 'lib/noty/models/snippet.rb', line 21

def open
  edit
end

#saveObject



13
14
15
# File 'lib/noty/models/snippet.rb', line 13

def save
  File.write(path, content)
end

#to_s(short = false) ⇒ Object



33
34
35
# File 'lib/noty/models/snippet.rb', line 33

def to_s(short = false)
  short ? content.tr("\n", ' ')[0..100] : content.to_s
end