class SimpleNoteParser::Organizer
Attributes
destination[RW]
file[RW]
Public Class Methods
new(file: "./source/notes.json", destination: "./dist/organized-by-tags")
click to toggle source
# File lib/simple_note_parser/organizer.rb, line 6 def initialize(file: "./source/notes.json", destination: "./dist/organized-by-tags") @file = file @destination = destination end
Public Instance Methods
organize_by_tag()
click to toggle source
# File lib/simple_note_parser/organizer.rb, line 11 def organize_by_tag json_data = load_json_data(file) notes = parse_json_data(json_data) process_notes(notes) end
Private Instance Methods
create_file(path, note)
click to toggle source
# File lib/simple_note_parser/organizer.rb, line 36 def create_file(path, note) first_line = note["content"].split("\r").first name = first_line.downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "") content = note["content"] File.open("#{path}/#{name}.txt", "w") { |f| f.write content } end
process_notes(notes)
click to toggle source
# File lib/simple_note_parser/organizer.rb, line 19 def process_notes(notes) notes.each do |note| tags = note["tags"] if tags.nil? || tags.empty? path = "#{destination}/no-tags" create_directory(path) create_file(path, note) else tags.each do |tag| path = "#{destination}/#{tag.downcase}" create_directory(path) create_file(path, note) end end end end