Class: Annoyme::NotesFile
- Inherits:
-
Object
- Object
- Annoyme::NotesFile
- Defined in:
- lib/annoyme/notes_file.rb
Instance Method Summary collapse
- #create ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(path) ⇒ NotesFile
constructor
A new instance of NotesFile.
- #parse ⇒ Object
- #write(content) ⇒ Object
Constructor Details
#initialize(path) ⇒ NotesFile
Returns a new instance of NotesFile.
5 6 7 |
# File 'lib/annoyme/notes_file.rb', line 5 def initialize(path) @path = path end |
Instance Method Details
#create ⇒ Object
9 10 11 12 13 |
# File 'lib/annoyme/notes_file.rb', line 9 def create File.open(@path, 'w') do |f| f.write("[]") end end |
#exists? ⇒ Boolean
15 16 17 |
# File 'lib/annoyme/notes_file.rb', line 15 def exists? File.exist?(@path) end |
#parse ⇒ Object
19 20 21 22 23 24 |
# File 'lib/annoyme/notes_file.rb', line 19 def parse content = File.readlines(@path).first JSON.parse(content) rescue JSON::ParserError raise 'notes file seems to be corrupted' end |
#write(content) ⇒ Object
26 27 28 29 30 |
# File 'lib/annoyme/notes_file.rb', line 26 def write(content) File.open(@path, 'w') do |f| f.write(content) end end |