Top Level Namespace

Defined Under Namespace

Classes: Note, QV

Instance Method Summary collapse

Instance Method Details

#display_list(search_term, matches, id = 0) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/qv/qv.rb', line 48

def display_list(search_term, matches, id = 0)
  system("clear")
  puts "#{search_term}: #{matches.count}"
  notes =  matches.take(IO.console.winsize.first-2)
  puts notes.map {|note| 
    if notes.index(note) == id
      "* #{note.title}"
    else
      note.title
    end
  }
end

#get_inputObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/qv/qv.rb', line 16

def get_input
  search_term = ""
  io = IO.console
  position = 0
  returned = false

  until returned
    char = io.getch
    case char
    when "\u007F" # backspace
      search_term.slice!(-1)
    when "\u0003" # C-c
      exit
    when "\e"  # esc
      exit
    when "\u0015" # C-u
      search_term.replace ""
    when "\r" # hard return
      returned = true
    when "\n" # C-j
      position = position + 1
    when "\v"  # C-k
      position = position - 1
    else
      search_term << char
    end
    matches = Note.sort_notes_by_date(get_matching_notes(search_term))
    display_list(search_term, matches, position)
  end
   matches[position]
end

#get_matching_notes(search_term) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/qv/qv.rb', line 4

def get_matching_notes(search_term)
  matches = 
    Note.get_notes.map do |note|
      if note.matches?(search_term) || note.title_matches?(search_term)
          note
      else
        nil
      end
    end
  matches.select { |note| note }
end