Class: Noty::Snippet
- Inherits:
-
Object
- Object
- Noty::Snippet
- Defined in:
- lib/noty/models/snippet.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #copy ⇒ Object
- #delete ⇒ Object
- #edit ⇒ Object
-
#initialize(path) ⇒ Snippet
constructor
A new instance of Snippet.
- #open ⇒ Object
- #save ⇒ Object
- #to_s(short = false) ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/noty/models/snippet.rb', line 6 def content @content end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/noty/models/snippet.rb', line 6 def path @path end |
Instance Method Details
#copy ⇒ Object
25 26 27 |
# File 'lib/noty/models/snippet.rb', line 25 def copy Helpers.copy content end |
#delete ⇒ Object
17 18 19 |
# File 'lib/noty/models/snippet.rb', line 17 def delete File.delete path end |
#open ⇒ Object
21 22 23 |
# File 'lib/noty/models/snippet.rb', line 21 def open edit end |
#save ⇒ Object
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 |