Class: Note
- Inherits:
-
Object
- Object
- Note
- Defined in:
- lib/note_taker/note.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #edit ⇒ Object
-
#initialize(filename) ⇒ Note
constructor
A new instance of Note.
- #view ⇒ Object
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
46 47 48 |
# File 'lib/note_taker/note.rb', line 46 def filename @filename end |
#location ⇒ Object (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
.create ⇒ Object
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 |
.dir ⇒ Object
31 32 33 |
# File 'lib/note_taker/note.rb', line 31 def dir NoteTaker.config['general']['directory'] end |
.prompt ⇒ Object
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( , filenames, filter: true, per_page: 40, help: '(or press ctrl+c to abort)', show_help: :always ) new(input) end |
Instance Method Details
#delete ⇒ Object
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 |
#edit ⇒ Object
67 68 69 |
# File 'lib/note_taker/note.rb', line 67 def edit TTY::Editor.open(file_path) end |
#view ⇒ Object
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.[:inline] ? puts(parsed) : prompt.puts(parsed) prompt.puts("\n") break if NoteTaker.inline? end end end |