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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae56ca25f841eaff18296862d348b30a4325b3a16d7a466f370ffc9be6c220de
4
- data.tar.gz: d74cfee5328f859cc5930c3d6b8732f943e429f4599515a6e15f4316a028ca74
3
+ metadata.gz: aa7c26ce44a5909155c4024167e1b0f43cda45951845094737555f464b16cdb1
4
+ data.tar.gz: ac429da7e7a807b15cd52bc274e1b1cb203eb6a8c42ebba1f1cf1ee3e45766f2
5
5
  SHA512:
6
- metadata.gz: 80d518dd0aa2bf1b29dbdbbb5def839cf8401b976fef6269de2620420341509e2919297ad845695914f278bf3bb377cc21ec81e56b0955b4d28fa39e399f6c81
7
- data.tar.gz: a3e2b7c5838efb034d3cfb54304ae2ed3b303fb02702da22a1c395708574b1360326687b12f8d51dbc3882d8717087ccd1ed2726c1a88ab3e0f3cc3f174e01b7
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.0)
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.16.2)
19
+ httparty (0.17.0)
20
+ mime-types (~> 3.0)
20
21
  multi_xml (>= 0.5.2)
21
- json (2.1.0)
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.16.4
61
+ 1.17.3
data/README.md CHANGED
@@ -1,13 +1,17 @@
1
1
  [![Build Status](https://travis-ci.org/bynarlogic/datamuse-rb.svg?branch=master)](https://travis-ci.org/bynarlogic/datamuse-rb)
2
+ [![Gem Version](https://badge.fury.io/rb/datamuse_rb.svg)](https://badge.fury.io/rb/datamuse_rb)
2
3
  [![Coverage Status](https://coveralls.io/repos/github/bynarlogic/datamuse-rb/badge.svg?branch=master)](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
- DatamuseResultList.new(response.parsed_response,queries)
13
+ DatamuseResults.new(response.parsed_response,queries)
14
14
  end
15
15
  end
16
16
 
17
- class DatamuseResultList
18
- extend Forwardable
19
- attr_accessor :results
20
- delegate [:first, :each] => :@results
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.first
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
- class DatamuseResult < OpenStruct
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
+
@@ -1,3 +1,3 @@
1
1
  module DatamuseRB
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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: 2018-10-09 00:00:00.000000000 Z
11
+ date: 2019-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler