ideapad 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +22 -0
- data/bin/idea +49 -0
- data/lib/ideapad/idea.rb +12 -0
- data/lib/ideapad/idea_list.rb +66 -0
- data/lib/ideapad.rb +11 -0
- metadata +51 -0
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
## WAT
|
2
|
+
|
3
|
+
This project is a dead-simple way to keep track of your ideas.
|
4
|
+
Currently, it has only a command line interface. The interface
|
5
|
+
is quite limited: you can add idea, view your ideas, and delete
|
6
|
+
ideas.
|
7
|
+
|
8
|
+
Ideas are Marshaled to disk at `~/.ideas.db`.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Adding an idea:
|
13
|
+
|
14
|
+
`idea add "the most brilliant idea for a cat meme ever"`
|
15
|
+
|
16
|
+
Listing all your ideas:
|
17
|
+
|
18
|
+
`idea list`
|
19
|
+
|
20
|
+
Delete the last idea:
|
21
|
+
|
22
|
+
`idea pop`
|
data/bin/idea
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
CMD = ARGV[0]
|
4
|
+
require './lib/ideapad'
|
5
|
+
include Ideapad
|
6
|
+
|
7
|
+
list = IdeaList.load!
|
8
|
+
|
9
|
+
# error and exit
|
10
|
+
def ee(msg)
|
11
|
+
$stderr.puts "An error occurred: #{msg}"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def halp!
|
16
|
+
msg = []
|
17
|
+
msg << "Usage: idea [command] [args]"
|
18
|
+
msg << "Commands: add, list, size, pop"
|
19
|
+
msg << ""
|
20
|
+
msg << ""
|
21
|
+
msg << "Adding an idea: `idea add this is the body of my idea. no quotes required, though, recommended.`"
|
22
|
+
msg << "Listing ideas: `idea list`"
|
23
|
+
msg << "Remove the last idea: `idea pop`"
|
24
|
+
|
25
|
+
puts msg.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
case CMD.downcase
|
29
|
+
when 'help'
|
30
|
+
halp!
|
31
|
+
when 'list', 'l'
|
32
|
+
list.pretty
|
33
|
+
when 'add', 'a'
|
34
|
+
idea = ARGV[1..-1]
|
35
|
+
if idea.nil? || idea == []
|
36
|
+
ee "idea required"
|
37
|
+
end
|
38
|
+
idea = idea.join(" ")
|
39
|
+
|
40
|
+
list.add_idea idea
|
41
|
+
list.pretty
|
42
|
+
when 'size', 'num'
|
43
|
+
puts list.size
|
44
|
+
when 'pop'
|
45
|
+
list.pop
|
46
|
+
list.pretty
|
47
|
+
else
|
48
|
+
halp!
|
49
|
+
end
|
data/lib/ideapad/idea.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
module Ideapad
|
3
|
+
class IdeaList
|
4
|
+
DB_NAME = '~/.ideas.db'
|
5
|
+
|
6
|
+
attr_reader :ideas
|
7
|
+
def initialize(ideas = [])
|
8
|
+
@ideas = Array(ideas)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Add an idea to the list
|
12
|
+
#
|
13
|
+
# @param [String] text the text of an idea
|
14
|
+
def add_idea(text)
|
15
|
+
idea = ideas.push(Idea.new(text))
|
16
|
+
save
|
17
|
+
idea
|
18
|
+
end
|
19
|
+
|
20
|
+
# Marshal the array of ideas to disk
|
21
|
+
def save
|
22
|
+
File.write(db, Marshal.dump(ideas))
|
23
|
+
end
|
24
|
+
|
25
|
+
def size
|
26
|
+
ideas.size
|
27
|
+
end
|
28
|
+
|
29
|
+
def first_idea_ts
|
30
|
+
ideas.first.timestamp if ideas.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def pop
|
34
|
+
ideas.pop
|
35
|
+
save
|
36
|
+
end
|
37
|
+
|
38
|
+
def pretty
|
39
|
+
msg = ["#{size} ideas recorded since #{first_idea_ts}"]
|
40
|
+
msg << ""
|
41
|
+
ideas.each_with_index do |idea, i|
|
42
|
+
msg << "[#{i+1}] => [#{idea.timestamp}] #{idea.text}"
|
43
|
+
end
|
44
|
+
puts msg.join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
def db
|
48
|
+
self.class.db
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.db
|
52
|
+
@db ||= File.expand_path(DB_NAME)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Read the DB file from disk, deserialize it and initialize an
|
56
|
+
# IdeaList instance
|
57
|
+
def self.load!
|
58
|
+
if File.exist?(db)
|
59
|
+
save
|
60
|
+
new Marshal.load(File.read(db))
|
61
|
+
else
|
62
|
+
new
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/ideapad.rb
ADDED
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ideapad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Sharp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Tiny utility for keeping track of ideas.
|
15
|
+
email:
|
16
|
+
- ajsharp@gmail.com
|
17
|
+
executables:
|
18
|
+
- idea
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- README.md
|
23
|
+
- bin/idea
|
24
|
+
- lib/ideapad.rb
|
25
|
+
- lib/ideapad/idea.rb
|
26
|
+
- lib/ideapad/idea_list.rb
|
27
|
+
homepage: https://github.com/ajsharp/ideapad
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project: ideapad
|
47
|
+
rubygems_version: 1.8.15
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Tiny utility for keeping track of ideas.
|
51
|
+
test_files: []
|