vocabulary 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 vocabulary.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Vocabulary
2
+
3
+ Wrapper for unofficial Google Dictionary API. *Fetch meanings and part of speech of `any` word of any language.*
4
+ You can find the list of supported languages (over 90) in [separated file](https://github.com/kirs/vocabulary/blob/master/languages.md)
5
+
6
+ ##Setup
7
+
8
+ Just add to your Gemfile:
9
+
10
+ gem "vocabularry", :git => "git://github.com/kirs/vocabulary.git"
11
+
12
+ ##Usage
13
+
14
+ Examples:
15
+
16
+ word = Vocabulary::lookup("kaunis", :fi)
17
+ word.part_of_speech
18
+ => "adjective"
19
+ word.meanings
20
+ => ["beautiful", "lovely", "pretty", "handsome", "fine", "nice", "fair"]
21
+
22
+ word = Vocabulary::lookup("яблоко", :ru)
23
+ word.part_of_speech
24
+ => "noun"
25
+ word.meanings
26
+ => ["apple"]
27
+
28
+ You can fetch meanings in any language:
29
+
30
+ word = Vocabulary::lookup("apple", :en, :ru)
31
+ word.part_of_speech
32
+ => "noun"
33
+ word.meanings
34
+ => ["яблоко", "яблоня", "лесть", "чепуха"]
35
+
36
+ ##Todo
37
+
38
+ - Add RSpec tests
39
+
40
+ ##Author
41
+
42
+ - [Kir Shatrov](https://github.com/kirs/) (Evrone Company)
43
+
44
+ ##Feel free for pull requests!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/languages.md ADDED
@@ -0,0 +1,91 @@
1
+ 1. AFRIKAANS: af,
2
+ 1. ALBANIAN: sq,
3
+ 1. AMHARIC: am,
4
+ 1. ARABIC: ar,
5
+ 1. ARMENIAN: hy,
6
+ 1. AZERBAIJANI: az,
7
+ 1. BASQUE: eu,
8
+ 1. BELARUSIAN: be,
9
+ 1. BENGALI: bn,
10
+ 1. BIHARI: bh,
11
+ 1. BULGARIAN: bg,
12
+ 1. BURMESE: my,
13
+ 1. CATALAN: ca,
14
+ 1. CHEROKEE: chr,
15
+ 1. CHINESE: zh,
16
+ 1. CHINESE_SIMPLIFIED: zh-CN,
17
+ 1. CHINESE_TRADITIONAL: zh-TW,
18
+ 1. CROATIAN: hr,
19
+ 1. CZECH: cs,
20
+ 1. DANISH: da,
21
+ 1. DHIVEHI: dv,
22
+ 1. DUTCH: nl,
23
+ 1. ENGLISH: en,
24
+ 1. ESPERANTO: eo,
25
+ 1. ESTONIAN: et,
26
+ 1. FILIPINO: tl,
27
+ 1. FINNISH: fi,
28
+ 1. FRENCH: fr,
29
+ 1. GALICIAN: gl,
30
+ 1. GEORGIAN: ka,
31
+ 1. GERMAN: de,
32
+ 1. GREEK: el,
33
+ 1. GUARANI: gn,
34
+ 1. GUJARATI: gu,
35
+ 1. HEBREW: iw,
36
+ 1. HINDI: hi,
37
+ 1. HUNGARIAN: hu,
38
+ 1. ICELANDIC: is,
39
+ 1. INDONESIAN: id,
40
+ 1. INUKTITUT: iu,
41
+ 1. IRISH: ga,
42
+ 1. ITALIAN: it,
43
+ 1. JAPANESE: ja,
44
+ 1. KANNADA: kn,
45
+ 1. KAZAKH: kk,
46
+ 1. KHMER: km,
47
+ 1. KOREAN: ko,
48
+ 1. KURDISH: ku,
49
+ 1. KYRGYZ: ky,
50
+ 1. LAOTHIAN: lo,
51
+ 1. LATVIAN: lv,
52
+ 1. LITHUANIAN: lt,
53
+ 1. MACEDONIAN: mk,
54
+ 1. MALAY: ms,
55
+ 1. MALAYALAM: ml,
56
+ 1. MALTESE: mt,
57
+ 1. MARATHI: mr,
58
+ 1. MONGOLIAN: mn,
59
+ 1. NEPALI: ne,
60
+ 1. NORWEGIAN: no,
61
+ 1. ORIYA: or,
62
+ 1. PASHTO: ps,
63
+ 1. PERSIAN: fa,
64
+ 1. POLISH: pl,
65
+ 1. PORTUGUESE: pt-PT,
66
+ 1. PUNJABI: pa,
67
+ 1. ROMANIAN: ro,
68
+ 1. RUSSIAN: ru,
69
+ 1. SANSKRIT: sa,
70
+ 1. SERBIAN: sr,
71
+ 1. SINDHI: sd,
72
+ 1. SINHALESE: si,
73
+ 1. SLOVAK: sk,
74
+ 1. SLOVENIAN: sl,
75
+ 1. SPANISH: es,
76
+ 1. SWAHILI: sw,
77
+ 1. SWEDISH: sv,
78
+ 1. TAJIK: tg,
79
+ 1. TAMIL: ta,
80
+ 1. TAGALOG: tl,
81
+ 1. TELUGU: te,
82
+ 1. THAI: th,
83
+ 1. TIBETAN: bo,
84
+ 1. TURKISH: tr,
85
+ 1. UKRAINIAN: uk,
86
+ 1. URDU: ur,
87
+ 1. UZBEK: uz,
88
+ 1. UIGHUR: ug,
89
+ 1. VIETNAMESE: vi,
90
+ 1. WELSH: cy,
91
+ 1. YIDDISH: yi,
data/lib/vocabulary.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'httparty'
2
+ require "vocabulary/version"
3
+
4
+ module Vocabulary
5
+ class Word
6
+ attr_accessor :part_of_speech, :meanings
7
+
8
+ def initialize summary
9
+ raise ArgumentError, "Bad summary" unless summary
10
+ @part_of_speech = summary["primaries"][0]["entries"][0]["labels"][0]["text"]
11
+
12
+ @meanings = []
13
+ summary["primaries"][0]["entries"][0]["entries"].each do |meaning|
14
+ @meanings << meaning["terms"][0]["text"]
15
+ end
16
+ end
17
+ end
18
+
19
+ class Dictionary
20
+ include HTTParty
21
+ format :plain
22
+ base_uri 'http://www.google.com/'
23
+
24
+ def get(word, source_lang, target_lang)
25
+ # example request
26
+ # /dictionary/json?callback=substr&q=apple&sl=en&tl=en&restrict=pr%2Cde&client=te
27
+ options = {}
28
+ options[:query] = {
29
+ :callback => "substr",
30
+ :q => word,
31
+ :sl => target_lang,
32
+ :tl => source_lang
33
+ }
34
+
35
+ response = self.class.get("/dictionary/json", options)
36
+ if response
37
+ info = response.parsed_response
38
+ json = info.gsub("substr(", "").gsub!(",200,null)", "")
39
+ JSON.parse(json)
40
+ end
41
+ end
42
+ end
43
+
44
+ def self.lookup(word, source_lang, target_lang = nil)
45
+ target_lang ||= :en
46
+ data = Disctionary.new.get(word, source_lang.to_s, target_lang.to_s)
47
+ Word.new(data)
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Vocabulary
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "vocabulary/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "vocabulary"
7
+ s.version = Vocabulary::VERSION
8
+ s.authors = ["Kir Shatrov"]
9
+ s.email = ["razor.psp@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Ruby wrapper for Google Dictionary API}
12
+ s.summary = %q{Ruby wrapper for Google Dictionary API}
13
+
14
+ s.rubyforge_project = "vocabulary"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "httparty"
24
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vocabulary
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kir Shatrov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70206039339440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70206039339440
25
+ description:
26
+ email:
27
+ - razor.psp@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - languages.md
37
+ - lib/vocabulary.rb
38
+ - lib/vocabulary/version.rb
39
+ - vocabulary.gemspec
40
+ homepage: ''
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project: vocabulary
60
+ rubygems_version: 1.8.10
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Ruby wrapper for Google Dictionary API
64
+ test_files: []