wordMatch 0.0.0
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 +7 -0
- data/lib/wordMatch.rb +58 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a38f470b1a11736cd316bad2264f6a65d1176638758b83963181d1db6b08b5e5
|
|
4
|
+
data.tar.gz: ee6820bfa5da3acfd728244f30fd9d0bdc8961757e1ffc35703d6acdd5c9078a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 90248e6179b63b4dee4578dc0e3cc9d9c018f386d54d9790d43e4a62ecadf618ecac0217fd0e5a48fe8a24f4d6c4ae5dfc0414a782e922f37cfbf16d3deecd54
|
|
7
|
+
data.tar.gz: fb5f9f9da92b0d6f199060b23836032157b178c37a5e5d1a65da1a49349806601d1b70170f0c6a23284362900cca037486e4598d5f8e085b868804184f5d33be
|
data/lib/wordMatch.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'pp'
|
|
4
|
+
|
|
5
|
+
class WordMatch
|
|
6
|
+
|
|
7
|
+
def self.containsWord(articles, word)
|
|
8
|
+
matches_arr = Array.new
|
|
9
|
+
articles.each do |article|
|
|
10
|
+
|
|
11
|
+
title = article["title"]
|
|
12
|
+
description = article["description"]
|
|
13
|
+
content = article["content"]
|
|
14
|
+
|
|
15
|
+
isTitle = !title.nil?
|
|
16
|
+
isDescription = !description.nil?
|
|
17
|
+
isContent = !content.nil?
|
|
18
|
+
|
|
19
|
+
found = false
|
|
20
|
+
|
|
21
|
+
if isTitle
|
|
22
|
+
if title.match(word)
|
|
23
|
+
found = true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
if isDescription
|
|
28
|
+
if description.match(word)
|
|
29
|
+
found = true
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
if isContent
|
|
34
|
+
if content.match(word)
|
|
35
|
+
found = true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if found
|
|
40
|
+
matches_arr.push(article)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if matches_arr.length < 1
|
|
45
|
+
str = "No Matches Found"
|
|
46
|
+
return str
|
|
47
|
+
|
|
48
|
+
else
|
|
49
|
+
arr_length = matches_arr.length
|
|
50
|
+
articles_json = JSON.generate(matches_arr)
|
|
51
|
+
articles_obj = JSON.parse(articles_json)
|
|
52
|
+
append_json = {"status":"ok","totalResults":arr_length,"articles":articles_obj}
|
|
53
|
+
return json = JSON.generate(append_json)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: wordMatch
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- AdamR
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-12-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: key word search for articles
|
|
14
|
+
email: x19401956@student.ncirl.ie
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/wordMatch.rb
|
|
20
|
+
homepage:
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.3.7
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Used to search for keywords in articles
|
|
43
|
+
test_files: []
|