datamuse_rb 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +8 -4
- data/README.md +5 -0
- data/lib/datamuse_rb.rb +43 -11
- data/lib/datamuse_rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa7c26ce44a5909155c4024167e1b0f43cda45951845094737555f464b16cdb1
|
4
|
+
data.tar.gz: ac429da7e7a807b15cd52bc274e1b1cb203eb6a8c42ebba1f1cf1ee3e45766f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5eeab797fb410203a1c01cae3534f3f255c170a04d48782808af6f8cdf4445ccedfe66171fdebb7035598427f5df348c14af43566f5f37180f4e4bf1568a37b
|
7
|
+
data.tar.gz: 26cb4dcb3a93ce93069c47a2bf7ce116b26e94624b86e91a7e6db2e1f162251ba198a7962aa3dca5823e2907ffd05c44d89a48c39738040481a5147ca2f596a1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
datamuse_rb (0.1.
|
4
|
+
datamuse_rb (0.1.2)
|
5
5
|
coveralls
|
6
6
|
httparty
|
7
7
|
|
@@ -16,9 +16,13 @@ GEM
|
|
16
16
|
tins (~> 1.6)
|
17
17
|
diff-lcs (1.3)
|
18
18
|
docile (1.3.1)
|
19
|
-
httparty (0.
|
19
|
+
httparty (0.17.0)
|
20
|
+
mime-types (~> 3.0)
|
20
21
|
multi_xml (>= 0.5.2)
|
21
|
-
json (2.
|
22
|
+
json (2.2.0)
|
23
|
+
mime-types (3.2.2)
|
24
|
+
mime-types-data (~> 3.2015)
|
25
|
+
mime-types-data (3.2019.0331)
|
22
26
|
multi_xml (0.6.0)
|
23
27
|
rake (10.5.0)
|
24
28
|
rspec (3.8.0)
|
@@ -54,4 +58,4 @@ DEPENDENCIES
|
|
54
58
|
rspec (~> 3.0)
|
55
59
|
|
56
60
|
BUNDLED WITH
|
57
|
-
1.
|
61
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
[](https://travis-ci.org/bynarlogic/datamuse-rb)
|
2
|
+
[](https://badge.fury.io/rb/datamuse_rb)
|
2
3
|
[](https://coveralls.io/github/bynarlogic/datamuse-rb?branch=master)
|
3
4
|
|
4
5
|
# DatamuseRb
|
5
6
|
|
7
|
+
**Deprecation Warning:** DatamuseRB will no longer extend the String class directly. String will only be extended within classes or modules using DatamuseRB starting in version 0.2.0. See the updated examples below.
|
8
|
+
|
6
9
|
DatamuseRb is yet another Ruby wrapper for the wonderful [Datamuse API](https://www.datamuse.com/api/). The approach for this gem is a little different. DatamuseRb extends the Ruby String Class with Datamuse methods. Methods can be chained much like the actual Datamuse API allows.
|
7
10
|
|
8
11
|
Example: Words related to duck that start with the letter b
|
9
12
|
|
10
13
|
```ruby
|
14
|
+
using DatamuseRB
|
11
15
|
"duck".means_like.spelled_like("b*")
|
12
16
|
```
|
13
17
|
|
@@ -34,6 +38,7 @@ DatamuseRB currently supports all of the /words functions. Please visit the [dat
|
|
34
38
|
Basic Usage:
|
35
39
|
|
36
40
|
```ruby
|
41
|
+
using DatamuseRB
|
37
42
|
#Call on any string
|
38
43
|
"ruby".means_like
|
39
44
|
=> #<DatamuseRB::DatamuseResult word="red", score=84986, tags=["syn", "n", "adj"]>
|
data/lib/datamuse_rb.rb
CHANGED
@@ -10,28 +10,41 @@ module DatamuseRB
|
|
10
10
|
|
11
11
|
def self.send(endpoint,**queries)
|
12
12
|
response = get(endpoint,query: queries)
|
13
|
-
|
13
|
+
DatamuseResults.new(response.parsed_response,queries)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
class DatamuseResult < OpenStruct
|
18
|
+
end
|
19
|
+
|
20
|
+
class DatamuseResults
|
21
|
+
include Enumerable
|
21
22
|
|
22
|
-
def initialize(response,query)
|
23
|
+
def initialize(response, query)
|
23
24
|
@results = response.map {|r| DatamuseResult.new(r)}
|
24
25
|
@query = query
|
25
26
|
end
|
26
27
|
|
28
|
+
def each(&block)
|
29
|
+
@results.each do |result|
|
30
|
+
block.call(result)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def empty?
|
35
|
+
none?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
27
40
|
def method_missing(name,*args)
|
28
|
-
super unless WORD_METHODS[name] && args.
|
41
|
+
super unless WORD_METHODS[name] && args.any?
|
29
42
|
@query.merge! WORD_METHODS[name] => args.first
|
30
43
|
DatamuseRequest.send("/words",@query)
|
31
44
|
end
|
32
|
-
end
|
33
45
|
|
34
|
-
|
46
|
+
attr_reader :results, :query
|
47
|
+
|
35
48
|
end
|
36
49
|
|
37
50
|
WORD_METHODS = {
|
@@ -43,15 +56,34 @@ module DatamuseRB
|
|
43
56
|
related_homophones: :rel_hom,consonant_match: :rel_cns
|
44
57
|
}
|
45
58
|
|
59
|
+
refine String do
|
60
|
+
WORD_METHODS.each do |k,v|
|
61
|
+
define_method(k) do
|
62
|
+
DatamuseRequest.send("/words",v => self)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def warning_message
|
68
|
+
<<~HEREDOC
|
69
|
+
DatamuseRB Deprecation Notice:
|
70
|
+
String will no longer be globally extended starting in version 0.2.0.
|
71
|
+
Add 'using DatamuseRB' to the module or class that uses this behavior.
|
72
|
+
For further details visit https://github.com/bynarlogic/datamuse-rb
|
73
|
+
HEREDOC
|
74
|
+
end
|
75
|
+
|
46
76
|
end
|
47
77
|
|
48
78
|
class String
|
49
79
|
include DatamuseRB
|
50
|
-
|
51
80
|
WORD_METHODS.each do |k,v|
|
52
81
|
define_method(k) do
|
82
|
+
warn(warning_message)
|
53
83
|
DatamuseRequest.send("/words",v => self)
|
54
84
|
end
|
55
85
|
end
|
56
|
-
|
57
86
|
end
|
87
|
+
|
88
|
+
|
89
|
+
|
data/lib/datamuse_rb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datamuse_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua D Jarvis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|