Class: Note

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Note

Returns a new instance of Note.



48
49
50
# File 'lib/note_taker/note.rb', line 48

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



46
47
48
# File 'lib/note_taker/note.rb', line 46

def filename
  @filename
end

#locationObject (readonly)

Returns the value of attribute location.



46
47
48
# File 'lib/note_taker/note.rb', line 46

def location
  @location
end

Class Method Details

.createObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/note_taker/note.rb', line 3

def create
  prompt.say('What is the filename of the note you want to create? (or press ctrl+c to abort)')
  input = prompt.ask('') do |q|
    q.required true
  end

  filepath = "#{ENV['HOME']}/#{dir}/#{input}.md".shellescape
  `touch #{filepath}`
  new(input)
end

.dirObject



31
32
33
# File 'lib/note_taker/note.rb', line 31

def dir
  NoteTaker.config['general']['directory']
end

.promptObject



35
36
37
# File 'lib/note_taker/note.rb', line 35

def prompt
  @prompt ||= TTY::Prompt.new(quiet: true, interrupt: -> { throw(:quit) })
end

.search(prompt_message: 'Choose a note.') ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/note_taker/note.rb', line 14

def search(prompt_message: 'Choose a note.')
  if filenames.empty?
    prompt.puts('Folder currently empty')
    return
  end

  input = prompt.select(
    prompt_message,
    filenames,
    filter: true,
    per_page: 40,
    help: '(or press ctrl+c to abort)',
    show_help: :always
  )
  new(input)
end

Instance Method Details

#deleteObject



71
72
73
74
75
# File 'lib/note_taker/note.rb', line 71

def delete
  return unless prompt.yes?("Are you sure you want to delete '#{filename}'")

  `rm #{file_path.shellescape}`
end

#editObject



67
68
69
# File 'lib/note_taker/note.rb', line 67

def edit
  TTY::Editor.open(file_path)
end

#viewObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/note_taker/note.rb', line 52

def view
  catch(:note_quit) do
    loop do
      NoteTaker.header unless NoteTaker.inline?
      parsed = TTY::Markdown.parse_file(file_path)
      NoteTaker.options[:inline] ? puts(parsed) : prompt.puts(parsed)
      prompt.puts("\n")

      break if NoteTaker.inline?

      note_menu
    end
  end
end