def 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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in def.gemspec
4
+ gemspec
data/README.markdown ADDED
@@ -0,0 +1,8 @@
1
+ This is a pretty simple script that you can define words with.
2
+ It will search dict.org and cache any results found in ~/.defs
3
+
4
+ $ def [word]
5
+
6
+ You can also supply multiple words
7
+
8
+ $ def [word1] [word2]
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/def ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
5
+
6
+ require 'def'
7
+
8
+ if ARGV.length == 0
9
+ puts "Usage: def [word]"
10
+ else
11
+ dict = Def::Dictionary.new
12
+ ARGV.each do |arg|
13
+ puts dict.define(arg)
14
+ end
15
+ end
data/def.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "def/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "def"
7
+ s.version = Def::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["brandon"]
10
+ s.email = ["brandonpao@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = "a command line dictionary"
13
+ s.description = "a command line dictionary"
14
+ s.description = "searches dict.org for a definition, and stores results locally
15
+ so subsequent searches will be cached"
16
+
17
+ s.rubyforge_project = "def"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ s.executables = ["def"]
24
+ s.add_dependency("sqlite3")
25
+ end
@@ -0,0 +1,3 @@
1
+ module Def
2
+ VERSION = "0.0.1"
3
+ end
data/lib/def.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'sqlite3'
2
+
3
+ module Def
4
+ class Dictionary
5
+ STORAGE = "#{ENV['HOME']}/.defs"
6
+
7
+ def initialize
8
+ @db = SQLite3::Database.new(STORAGE)
9
+ setup_db
10
+ end
11
+
12
+ def define(word)
13
+ definition = get_from_history(word)
14
+ if definition
15
+ return highlight_word(word, definition)
16
+ end
17
+
18
+ definition = `curl -s dict://dict.org/d:#{word}`.split("\n")
19
+ definition = definition.slice(4, definition.size-6)
20
+
21
+ if definition.nil?
22
+ "No definition found for \033[0;32m#{word}\033[0m"
23
+ else
24
+ definition = definition.join("\n")
25
+ save_to_history(word, definition)
26
+ highlight_word(word, definition)
27
+ end
28
+ end
29
+
30
+ def highlight_word(word, definition)
31
+ definition.gsub(/(#{word})/i, "\033[0;32m\\1\033[0m")
32
+ end
33
+
34
+ def get_from_history(word)
35
+ @db.get_first_value("SELECT d FROM d WHERE w = ?", word)
36
+ end
37
+
38
+ def save_to_history(word, definition)
39
+ @db.execute('INSERT INTO d (w, d) VALUES (?, ?)', word, definition)
40
+ end
41
+
42
+ def setup_db
43
+ @db.query('CREATE TABLE IF NOT EXISTS d(w TEXT PRIMARY KEY, d TEXT NOT NULL);')
44
+ end
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: def
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease: !!null
6
+ platform: ruby
7
+ authors:
8
+ - brandon
9
+ autorequire: !!null
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-02-10 00:00:00.000000000 -05:00
13
+ default_executable: !!null
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sqlite3
17
+ requirement: &2153484120 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2153484120
26
+ description: ! "searches dict.org for a definition, and stores results locally\n so
27
+ subsequent searches will be cached"
28
+ email:
29
+ - brandonpao@gmail.com
30
+ executables:
31
+ - def
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - README.markdown
38
+ - Rakefile
39
+ - bin/def
40
+ - def.gemspec
41
+ - lib/def.rb
42
+ - lib/def/version.rb
43
+ has_rdoc: true
44
+ homepage: ''
45
+ licenses: []
46
+ post_install_message: !!null
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: def
64
+ rubygems_version: 1.5.0
65
+ signing_key: !!null
66
+ specification_version: 3
67
+ summary: a command line dictionary
68
+ test_files: []