wordfor 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wordfor.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adam Bachman
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.
@@ -0,0 +1,29 @@
1
+ # Wordfor
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'wordfor'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wordfor
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'optparse'
5
+ require 'wordfor'
6
+
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+ opts.banner = <<-EOS
11
+ wordfor is a command line thesaurus.
12
+
13
+ Usage:
14
+
15
+ wordfor [options] WORD
16
+
17
+ NOTE: You have to get an API key from http://words.bighugelabs.com/api.php to
18
+ use this program.
19
+
20
+ EOS
21
+
22
+ opts.on('-v', '--verbose', 'more noisy') do |v|
23
+ options[:verbose] = v
24
+ end
25
+
26
+ opts.on('-d', '--debug', 'debugging output') do |d|
27
+ options[:debug] = d
28
+ end
29
+ end.parse!
30
+
31
+ word = ARGV[0]
32
+
33
+ if word.nil?
34
+ puts "You must give a word to look up."
35
+ exit 1
36
+ else
37
+ word = word.strip
38
+ end
39
+
40
+ if Wordfor::Setup.run_setup?
41
+ Wordfor::Setup.new($stdin, $stdout).run
42
+ end
43
+
44
+ result = Wordfor::Lookup.new( Wordfor::Configuration.api_key ).lookup(word)
45
+
46
+ if options[:debug]
47
+ puts result.inspect
48
+ puts result.keys.inspect
49
+ end
50
+
51
+ result.each_pair do |(part_of_speech, words)|
52
+ if words
53
+ puts "#{ part_of_speech }:"
54
+
55
+ if words['syn']
56
+ word_list = words['syn'].join(", ")
57
+
58
+ puts " synonyms:"
59
+ puts ' ' + Wordfor::Plaintext.wrapped_text(word_list, :indent => ' ')
60
+ end
61
+
62
+ if words['ant']
63
+ word_list = words['ant'].join(", ")
64
+
65
+ puts " antonyms:"
66
+ puts ' ' + Wordfor::Plaintext.wrapped_text(word_list, :indent => ' ')
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ require 'httparty'
2
+
3
+ require 'wordfor/core_ext/array'
4
+
5
+ require 'wordfor/version'
6
+ require 'wordfor/configuration'
7
+ require 'wordfor/setup'
8
+ require 'wordfor/plaintext'
9
+ require 'wordfor/lookup'
10
+
11
+ module Wordfor
12
+ def self.logger
13
+ @logger ||= Logger.new(Configuration.log_file, 1, 1024000)
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'etc'
2
+
3
+ module Wordfor
4
+ class Configuration
5
+ class << self
6
+ def method_missing(method)
7
+ config[method.to_s]
8
+ end
9
+
10
+ def config
11
+ @config ||= YAML.load(File.open(config_file))
12
+ end
13
+
14
+ def config_file
15
+ user = Etc.getlogin
16
+ File.join(Dir.home(user), ".wordfor.yml")
17
+ end
18
+
19
+ def log_file
20
+ user = Etc.getlogin
21
+ File.join(Dir.home(user), ".wordfor.log")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # borrowed from ActiveSupport
2
+ class Array
3
+ def extract_options!
4
+ last.is_a?(Hash) ? pop : {}
5
+ end
6
+ end
7
+
@@ -0,0 +1,17 @@
1
+ require 'httparty'
2
+
3
+ # http://words.bighugelabs.com/api/2/API_KEY/word/json
4
+ module Wordfor
5
+ class Lookup
6
+ include HTTParty
7
+ base_uri 'words.bighugelabs.com'
8
+
9
+ def initialize(api_key)
10
+ @api_key = api_key
11
+ end
12
+
13
+ def lookup(word)
14
+ self.class.get("/api/2/#{ @api_key }/#{ word }/json")
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,63 @@
1
+ module Wordfor
2
+ class Plaintext
3
+ class << self
4
+ def print message=nil
5
+ puts message
6
+ end
7
+
8
+ # turn line into lines of text of columns length
9
+ def wrapped_text *args
10
+ options = {
11
+ :line_width => columns
12
+ }.merge args.extract_options!
13
+
14
+ line = args.shift
15
+
16
+ word_wrap(line, options)
17
+ end
18
+
19
+ private
20
+
21
+ def word_wrap(text, options={})
22
+ options = {
23
+ :line_width => columns,
24
+ :preserve_whitespace => false
25
+ }.merge options
26
+
27
+ unless options[:preserve_whitespace]
28
+ text = text.gsub(/\s+/, ' ') # collapse whitespace
29
+ end
30
+
31
+ prefix = options[:indent] ? options[:indent] : ''
32
+
33
+ line_width = options[:line_width]
34
+ lines = ['']
35
+
36
+ space = ' '
37
+ space_size = 2
38
+ space_left = line_width
39
+ text.split.each do |word|
40
+ if (word.size + space.size) >= space_left
41
+ word = "%s%s" % [prefix, word]
42
+ space_left = line_width - (word.size + space_size)
43
+ lines << ""
44
+ else
45
+ space_left = space_left - (word.size + space_size)
46
+ end
47
+
48
+ lines.last << "%s%s" % [word, space]
49
+ end
50
+
51
+ lines.join "\n"
52
+ end
53
+
54
+ def columns
55
+ @columns || (begin
56
+ @columns = `stty size`.split.last.to_i
57
+ rescue
58
+ @columns = 80
59
+ end)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,23 @@
1
+ module Wordfor
2
+ class Setup
3
+ def self.run_setup?
4
+ !File.exists?(Wordfor::Configuration.config_file)
5
+ end
6
+
7
+ def initialize(stdin, stdout)
8
+ @stdin = stdin
9
+ @stdout = stdout
10
+ @settings = {}
11
+ end
12
+
13
+ def run
14
+ File.open(Wordfor::Configuration.config_file, "w") do |file|
15
+ @stdout.puts "~/.wordfor.yml not found. Running setup"
16
+ @stdout.puts "http://words.bighugelabs.com/ API key?"
17
+ @settings["api_key"] = @stdin.gets.chomp
18
+ file.write @settings.to_yaml
19
+ end
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,3 @@
1
+ module Wordfor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wordfor/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "wordfor"
8
+ gem.version = Wordfor::VERSION
9
+ gem.authors = ["Adam Bachman"]
10
+ gem.email = ["adam.bachman@gmail.com"]
11
+ gem.description = %q{Find synonyms and antonyms from the command line.}
12
+ gem.summary = %q{A thesaurus for your command line.}
13
+ gem.homepage = "http://github.com/abachman/wordfor"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency('httparty', '~> 0.9.0')
21
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordfor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Bachman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.0
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: 0.9.0
30
+ description: Find synonyms and antonyms from the command line.
31
+ email:
32
+ - adam.bachman@gmail.com
33
+ executables:
34
+ - wordfor
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/wordfor
44
+ - lib/wordfor.rb
45
+ - lib/wordfor/configuration.rb
46
+ - lib/wordfor/core_ext/array.rb
47
+ - lib/wordfor/lookup.rb
48
+ - lib/wordfor/plaintext.rb
49
+ - lib/wordfor/setup.rb
50
+ - lib/wordfor/version.rb
51
+ - wordfor.gemspec
52
+ homepage: http://github.com/abachman/wordfor
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.24
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: A thesaurus for your command line.
76
+ test_files: []