boomboom 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ tmp.rb
19
+ notes.md
20
+ issues.md
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boomboom.gemspec
4
+ gemspec
5
+
6
+ gem 'json', '~> 1.7.3'
7
+ gem 'clipboard', '~> 1.0.1'
8
+ gem 'launchy', '~> 2.1.0'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Prasanna N
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ ## BoomBoom
2
+
3
+ It's all about trying to implement @holman's `boom` by myself.
4
+
5
+ ### v1 goal
6
+ To be able copy the given text to the system clipboard. Pretty simple uh?!
7
+ Let me find that..
8
+
9
+ ### v2 goal
10
+ To be able to store and retrieve the data from a text file.
11
+
12
+ ### v3 goal
13
+ To make it a full fledged command-line app.
14
+
15
+ ### v4 goal
16
+ To bundle it as a gem.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/boomboom ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require '../lib/boomboom'
4
+ require 'boomboom'
5
+
6
+ my_boom = BoomBoom.new
7
+
8
+ loop do
9
+ puts "......qq to quit...p to print......"
10
+ argv = gets.chomp
11
+ break if argv == 'qq'
12
+ if argv == 'p'
13
+ p my_boom.boom
14
+ next
15
+ end
16
+ argv = argv.split ' '
17
+
18
+ case argv.length
19
+ when 0
20
+ # print all the lists and the number of items in them
21
+ my_boom.print_boom_count
22
+
23
+ when 1
24
+ if argv[0] == 'help'
25
+ my_boom.show_help
26
+ elsif argv[0] == 'all'
27
+ my_boom.print_all
28
+ # If the argument is an existing list item, then copy it
29
+ elsif my_boom.has_item? argv[0]
30
+ my_boom.copy_to_clipboard(my_boom.get_item argv[0])
31
+ # If the argument is an existing list, then print the list items
32
+ elsif my_boom.has_list?(argv[0])
33
+ my_boom.print_list argv[0]
34
+ # otherwise, create a new list
35
+ else
36
+ my_boom.create_list argv[0]
37
+ end
38
+
39
+ when 2
40
+ if argv.last == 'delete'
41
+ # delete the entire list
42
+ my_boom.delete_list argv[0]
43
+ elsif argv.first == 'open'
44
+ # open the 'target' in the default browser
45
+ my_boom.open argv[1]
46
+ elsif argv.first == 'echo'
47
+ if my_boom.has_item? argv[1]
48
+ puts my_boom.get_item argv[1]
49
+ else
50
+ puts "#{argv[1]} not found."
51
+ end
52
+ elsif argv.first == 'random'
53
+ # open a random item's url for a list in browser
54
+ my_boom.open_random_item_in_list argv[1]
55
+ else
56
+ my_boom.copy_to_clipboard(my_boom.get_list_item argv[0], argv[1])
57
+ end
58
+
59
+ when 3
60
+ if argv.last == 'delete'
61
+ # delete a particular item in the list
62
+ my_boom.delete_list_item argv[0], argv[1]
63
+ elsif argv.first == 'echo'
64
+ puts my_boom.get_list_item argv[1], argv[2]
65
+ else
66
+ my_boom.set_list_item argv[0], argv[1], argv[2]
67
+ end
68
+ end
69
+ end
70
+
71
+ my_boom.write
data/boomboom.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/boomboom/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Prasanna N"]
6
+ gem.email = ["prasann87@gmail.com"]
7
+ gem.description = %q{My Implementation of @holman's boom [https://github.com/holman/boom/]}
8
+ gem.summary = %q{Just for practice I implemented @holman's boom [https://github.com/holman/boom/]. The goal was to create a similar funcionality on my own and then compare it with his code, (and then blog about it ofcourse!) so I could learn some good practices.}
9
+ gem.homepage = "https://github.com/npras/boomboom"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "boomboom"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Boomboom::VERSION
17
+ gem.executables << 'boomboom'
18
+ gem.add_dependency('json', '~> 1.7.3')
19
+ gem.add_dependency('clipboard', '~> 1.0.1')
20
+ gem.add_dependency('launchy', '~> 2.1.0')
21
+ gem.post_install_message = %q|
22
+
23
+ ***********************************************************
24
+
25
+ BoomBoom!!
26
+ Become a Commandline Magician!
27
+ Say thanks to @holman (he dreamt of the idea first)
28
+ and npras@github (he implemented it in his own style!).
29
+
30
+ ***********************************************************
31
+ |
32
+ end
@@ -0,0 +1,3 @@
1
+ module Boomboom
2
+ VERSION = "0.0.1"
3
+ end
data/lib/boomboom.rb ADDED
@@ -0,0 +1,179 @@
1
+ require 'json'
2
+ require 'clipboard'
3
+ require 'launchy'
4
+ require 'pry'
5
+
6
+ class BoomBoom
7
+ attr_reader :boom
8
+ DATAFILE = '.boomboom'
9
+
10
+ def initialize
11
+ @boom = read || {}
12
+ end
13
+
14
+ def create_list(list)
15
+ @boom[list] = {}
16
+ puts "Boom! Created a new list called #{list.upcase}."
17
+ end
18
+
19
+ def has_list?(list)
20
+ @boom.include? list
21
+ end
22
+
23
+ def has_item?(item)
24
+ @boom.any? do |k,v|
25
+ v.include? item
26
+ end
27
+ end
28
+
29
+ def get_item(item)
30
+ @boom.each do |k,v|
31
+ begin
32
+ return v.fetch item
33
+ rescue KeyError
34
+ next
35
+ end
36
+ end
37
+ nil
38
+ end
39
+
40
+ def get_list_item(list, item)
41
+ the_list = @boom.fetch list
42
+ begin
43
+ value = the_list.fetch item
44
+ rescue
45
+ puts "#{item} not found in #{list}"
46
+ end
47
+ value
48
+ rescue KeyError
49
+ puts "Oops! list #{list.upcase} not found... but we'll create it..."
50
+ create_list list
51
+ end
52
+
53
+ def copy_to_clipboard(txt)
54
+ return if txt.nil?
55
+ Clipboard.copy txt
56
+ puts "Boom! We just copied #{txt} to your clipboard."
57
+ end
58
+
59
+ def set_list_item(list, item, value)
60
+ create_list list unless has_list? list
61
+ @boom[list][item] = value
62
+ puts "#{item} in #{list} is #{value}. Got it."
63
+ end
64
+
65
+ def delete_list(list)
66
+ @boom.fetch list
67
+ puts "You sure you want to delete everything in #{list}? (y/n):\n"
68
+ decision = gets
69
+ decision.chop!
70
+ if decision == ?y
71
+ @boom.delete list
72
+ puts "Boom! Deleted all your #{list}."
73
+ elsif decision == ?n
74
+ puts "Just kidding then."
75
+ end
76
+ rescue KeyError
77
+ puts "The list #{list.upcase} doesn't exist."
78
+ end
79
+
80
+ def delete_list_item(list, item)
81
+ @boom.fetch list
82
+ begin
83
+ value = @boom[list].fetch item
84
+ rescue KeyError
85
+ puts "The item #{item} doesn't exist in the list #{list}."
86
+ return
87
+ end
88
+ @boom[list].delete item
89
+ puts "Boom! #{item} in #{list} is gone forever. It was #{value}."
90
+ rescue KeyError
91
+ puts "The list #{list} doesn't exist."
92
+ end
93
+
94
+ def print_list(list)
95
+ @boom[list].each do |k,v|
96
+ puts " #{k}:\t\t#{v}\n"
97
+ end
98
+ end
99
+
100
+ def print_all
101
+ @boom.keys.each do |k|
102
+ puts " #{k}"
103
+ print_list k
104
+ end
105
+ end
106
+
107
+ def print_boom_count
108
+ @boom.each do |k,v|
109
+ puts " #{k}\t (#{v.size})"
110
+ end
111
+ end
112
+
113
+ def open(target)
114
+ if has_item? target
115
+ item = get_item target
116
+ Launchy.open item
117
+ puts "Boom! We just opened #{item} for you."
118
+ elsif has_list? target
119
+ @boom[target].each do |k,v|
120
+ Launchy.open v
121
+ end
122
+ puts "Boom! We just opened all of \"#{target}\" for you."
123
+ else
124
+ puts "#{target} not found."
125
+ end
126
+ end
127
+
128
+ def open_random_item_in_list(list)
129
+ if has_list? list
130
+ the_list = @boom[list]
131
+ rand_item = the_list.keys[rand the_list.size]
132
+ open rand_item
133
+ else
134
+ puts "#{list} not found."
135
+ end
136
+ end
137
+
138
+ def write
139
+ data_str = @boom.to_json
140
+ File.open(ENV['HOME']+'/'+DATAFILE, 'w') do |f|
141
+ f << data_str
142
+ end
143
+ end
144
+
145
+ def read
146
+ begin
147
+ file_lines = File.open(ENV['HOME']+'/'+DATAFILE, 'r') do |f|
148
+ f.readlines
149
+ end
150
+ rescue Errno::ENOENT
151
+ File.new(ENV['HOME']+'/'+DATAFILE, 'w')
152
+ file_lines = []
153
+ end
154
+ return nil if file_lines.empty?
155
+ JSON.parse file_lines.first
156
+ end
157
+
158
+ def show_help
159
+ puts "---My Boom help---"
160
+ puts "boomboom\t\t display high-level overview"
161
+ puts "boomboom all\t\t show all items in all lists"
162
+ puts "boomboom help\t\t this help text"
163
+ puts
164
+ puts "boomboom <list>\t\t create a new list"
165
+ puts "boomboom <list>\t\t show items for a list"
166
+ puts "boomboom <list> delete\t\t deletes a list"
167
+ puts
168
+ puts "boomboom <list> <item> <value>\t\t create a new list item"
169
+ puts "boomboom <name>\t\t copy item's value to clipboard"
170
+ puts "boomboom <list> <name>\t\t copy item's value to clipboard"
171
+ puts "boomboom open <name>\t\t open item's url in browser"
172
+ puts "boomboom open <list>\t\t open all item in a list in browser"
173
+ puts "boomboom random\t\t open a random item's url in browser"
174
+ puts "boomboom echo <name>\t\t echo the item's value without copying"
175
+ puts
176
+ puts "boomboom <list> <name> delete\t\t delete an item"
177
+ puts "boomboom <list> delete\t\t delete all items in a list"
178
+ end
179
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boomboom
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Prasanna N
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.7.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.7.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: clipboard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: launchy
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.1.0
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.0
62
+ description: My Implementation of @holman's boom [https://github.com/holman/boom/]
63
+ email:
64
+ - prasann87@gmail.com
65
+ executables:
66
+ - boomboom
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - bin/boomboom
76
+ - boomboom.gemspec
77
+ - lib/boomboom.rb
78
+ - lib/boomboom/version.rb
79
+ homepage: https://github.com/npras/boomboom
80
+ licenses: []
81
+ post_install_message: ! "\n\n ***********************************************************\n\n
82
+ \ BoomBoom!!\n Become a Commandline Magician!\n Say thanks to @holman (he dreamt
83
+ of the idea first)\n and npras@github (he implemented it in his own style!).\n\n
84
+ \ ***********************************************************\n "
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Just for practice I implemented @holman's boom [https://github.com/holman/boom/].
106
+ The goal was to create a similar funcionality on my own and then compare it with
107
+ his code, (and then blog about it ofcourse!) so I could learn some good practices.
108
+ test_files: []
109
+ has_rdoc: