Class: Note

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Note

Returns a new instance of Note.



6
7
8
9
10
# File 'lib/qv/note.rb', line 6

def initialize(args)
  @filename = args[:file]
  @title = title
  @path = path
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/qv/note.rb', line 4

def filename
  @filename
end

Class Method Details

.get_notesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/qv/note.rb', line 44

def self.get_notes
  note_names = Dir.entries(QV.notes_dir).reject do |note_filename|
    exceptions = [
      "..",
      ".",
      "Interim Note-Changes",
      "Notes & Settings"
    ]
    exceptions.include?(note_filename) || 
      note_filename.start_with?(".")
  end
  note_names.map do |file|
    Note.new(:file => file)
  end
end

.sort_notes_by_date(notes) ⇒ Object



38
39
40
41
42
# File 'lib/qv/note.rb', line 38

def self.sort_notes_by_date(notes)
  notes.sort_by! { |note|
    File.mtime(note.path)}
  notes.reverse!
end

Instance Method Details

#editObject



32
33
34
35
36
# File 'lib/qv/note.rb', line 32

def edit
  editor = ENV["EDITOR"] || '/usr/bin/vim'
  exec "#{editor} \"#{path}\";clear"
  system "clear"
end

#get_ioObject



20
21
22
# File 'lib/qv/note.rb', line 20

def get_io
  File.open(@path)
end

#matches?(search_term) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/qv/note.rb', line 24

def matches?(search_term)
  get_io.read.match(/^.*#{search_term}.*$/i)
end

#pathObject



16
17
18
# File 'lib/qv/note.rb', line 16

def path
  @path || File.join(QV.notes_dir,@filename)
end

#titleObject



12
13
14
# File 'lib/qv/note.rb', line 12

def title
  @title || File.basename(@filename, File.extname(@filename))
end

#title_matches?(search_term) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/qv/note.rb', line 28

def title_matches?(search_term)
  @title.match(/^.*#{search_term}.*$/i)
end