Skip to content

Instantly share code, notes, and snippets.

@ryzokuken
Created September 23, 2015 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryzokuken/1fdc6c30c354a1e57228 to your computer and use it in GitHub Desktop.
Save ryzokuken/1fdc6c30c354a1e57228 to your computer and use it in GitHub Desktop.
Save: Save notes on the go
# Save.rb : Ujjwal Sharma and Kush Bansal
class Note
attr_reader :text, :title, :color
def initialize(text,title,color)
@text = text
@title = title
@color = color
end
def marshal_dump
[@text, @title, @color]
end
def marshal_load array
@text, @title, @color = array
end
end
notes = []
Shoes.app title: "Save" do
stack do
flow do
para strong "Clipboard: "
@para = para
end
@save = button "Save"
button "Show All" do
window do
stack do
number = notes.count
if number == 0
para strong "Notebook Empty. Save notes more often"
else
para strong "#{number} notes is notebook"
notes.each do |note|
stack do
background note.color
para strong note.title
para note.text
end
end
end
button "Close" do
close
end
end
end
end
button "Exit" do
File.open("notes.sv", 'w+') do |f|
notes.each do |note|
f.write(Marshal.dump(note))
end
end
alert "Saved notes on disk for later."
exit
end
end
animate do
text = clipboard
if text == nil
@para.replace "clipboard empty."
else
@para.replace text
@save.click do
title = ask "Enter a title for your new note"
color = ask_color "Enter a color for your new note"
note = Note.new(text,title,color)
notes.push(note)
end
end
end
end
@ollie
Copy link

ollie commented Sep 23, 2015

Hi there, take a look at those standard libraries shipped with Ruby:

Advantage with PStore is that it handles the persistence for you, no need load a file, read or parse file contents. However it is not very hard to make your own little store.

@fappelman
Copy link

You could actually look at this article that gives a bit more background: https://www.krautcomputing.com/blog/2015/09/21/rubys-built-in-databases-meet-pstore-and-yamlstore/

@ryzokuken
Copy link
Author

Thanks @ollie and @fappelman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment