Module: Note

Defined in:
lib/note.rb,
lib/note/version.rb

Constant Summary collapse

VERSION =
"0.7.6"

Instance Method Summary collapse

Instance Method Details

#check_fileObject

Your code goes here…



6
7
8
# File 'lib/note.rb', line 6

def check_file
  `touch #{notes}` unless File.exist? notes
end

#create(key) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/note.rb', line 23

def create(key)
  print "what value do you want to assign to this key? "
  string = STDIN.gets.strip
  hash = get_hash
  hash = {} if hash == nil
  hash[key] = string
  save_hash hash
end

#delete(key) ⇒ Object



32
33
34
35
36
# File 'lib/note.rb', line 32

def delete(key)
  hash = get_hash
  hash.delete(key)
  save_hash(hash)
end

#execute(key) ⇒ Object



38
39
40
# File 'lib/note.rb', line 38

def execute(key)
  exec(get_hash[key])
end

#get_hashObject



14
15
16
17
# File 'lib/note.rb', line 14

def get_hash
  check_file
  eval(File.open(notes, 'r') { |f| f.read })
end

#helpObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/note.rb', line 56

def help
  puts ""
  puts "note -l        Lists all note names"
  puts "note -c <key>  Create a new note"
  puts "note -d <key>  Delete a existing note"
  puts "note -e <key>  Try executing the key"
  puts "  - Execute has been shortcutted to 'sc' ie 'sc ping'"
  puts "note -h        Display Help"
  puts "note <key>     Display the note for the given key"
  puts ""
end

#listObject



50
51
52
53
54
# File 'lib/note.rb', line 50

def list
  get_hash.each do |key, value|
    puts key
  end
end

#notesObject



10
11
12
# File 'lib/note.rb', line 10

def notes
  "#{ENV['HOME']}/.notes"
end

#save_hash(hash) ⇒ Object



19
20
21
# File 'lib/note.rb', line 19

def save_hash(hash)
  File.open(notes, "w").write(hash.to_s)
end

#show(key) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/note.rb', line 42

def show(key)
  if get_hash[key]
    puts get_hash[key]
  else
    puts "Key does not exist."
  end
end