dephine 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dephine.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sina Samavati
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,31 @@
1
+ # Dephine
2
+
3
+ Google dictionary in terminal
4
+
5
+ ## Installation
6
+
7
+ $ gem install dephine
8
+
9
+ ## Usage
10
+
11
+ $ dephine [word]
12
+
13
+ ## What it looks like
14
+
15
+ $ dephine anything
16
+ anything
17
+
18
+ pronoun /ˈenēˌTHiNG/
19
+ Used for emphasis
20
+ - I was ready for anything
21
+
22
+ Used to indicate a range
23
+ - he trains anything from seven to eight hours a day
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/dephine ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.expand_path(File.dirname(__FILE__)), %w[.. lib])
4
+ require 'dephine'
5
+
6
+ banner = <<-END
7
+ Dephine, Google dictionary in terminal
8
+ Usage: dephine [word]
9
+ END
10
+
11
+ if ARGV.empty?
12
+ puts banner
13
+ else
14
+ word = Dephine::Dictionary.new(ARGV[0])
15
+
16
+ if word.meanings.empty?
17
+ abort("Word not found in the dictionary!")
18
+ end
19
+
20
+ puts ARGV[0]
21
+ word.meanings.each do |m|
22
+ puts
23
+ puts "#{m[:type].downcase} #{m[:phonetic]}"
24
+ m[:meanings].each do |d|
25
+ puts " #{d[:text]}"
26
+ d[:examples].each do |eg|
27
+ puts " - #{eg}"
28
+ end
29
+ puts
30
+ end
31
+ end
32
+ end
data/dephine.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dephine/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "dephine"
8
+ gem.version = Dephine::VERSION
9
+ gem.authors = ["Sina Samavati"]
10
+ gem.email = ["contact@s1n4.com"]
11
+ gem.summary = %q{Google dictionary in terminal}
12
+ gem.homepage = "https://github.com/s1n4/dephine"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ end
data/lib/dephine.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'dephine/version'
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Dephine
6
+ class Dictionary
7
+ # Public: Returns the Array meanings of the word.
8
+ attr_reader :meanings
9
+
10
+ # Public: Initialize some definitions of a word.
11
+ #
12
+ # word - A String to be defined.
13
+ def initialize(word)
14
+ raise ArgumentError, "Word shouldn't be blank" if word.empty?
15
+
16
+ @meanings = []
17
+ url = "https://www.google.com/dictionary/json?callback=define&q=#{word}&" \
18
+ "sl=en&tl=en&restrict=pr%2Cde&client=te"
19
+
20
+ # fetch and parse the json document
21
+ content = JSON.parse(open(url).read[7..-11])
22
+
23
+ content['primaries'].each do |primary|
24
+ @meanings << {
25
+ type: primary['terms'][0]['labels'][0]['text'],
26
+ phonetic: primary['terms'][1]['text'],
27
+ meanings: []
28
+ }
29
+
30
+ # add meanings
31
+ primary['entries'][1..-1].each do |entry|
32
+ @meanings[-1][:meanings] << {
33
+ text: entry['terms'][0]['text'].gsub('x27', "'") \
34
+ .gsub(/x3.*?3e/, ''),
35
+ examples: []
36
+ }
37
+
38
+ # add examples of a meaning
39
+ if entry.has_key?('entries')
40
+ entry['entries'].each do |eg|
41
+ @meanings[-1][:meanings][-1][:examples] << eg['terms'][0]['text'] \
42
+ .gsub('x27', "'").gsub(/x3.*?3e/, '')
43
+ end
44
+ end
45
+ end if primary.has_key?('entries')
46
+ end if content.has_key?('primaries')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Dephine
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dephine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sina Samavati
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email:
16
+ - contact@s1n4.com
17
+ executables:
18
+ - dephine
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/dephine
28
+ - dephine.gemspec
29
+ - lib/dephine.rb
30
+ - lib/dephine/version.rb
31
+ homepage: https://github.com/s1n4/dephine
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.24
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Google dictionary in terminal
55
+ test_files: []
56
+ has_rdoc: