dxtitle_search 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df32efa0600562a68efdde1eb315b79444c5b33b1ba32a4784976819ac62c241
4
- data.tar.gz: 683deed83c63b4e755ff02b084e3b3e7d436248eb1a6db62fe0bb2e511024e08
3
+ metadata.gz: febca2af1d5f671487bb3a374e0ce3a3a1c9d1bc61a365a7e264da32f2865d44
4
+ data.tar.gz: 8fb8561355abb9b169b789fa9388e6c70f12c92521d4dea14594ab74e8ad69d9
5
5
  SHA512:
6
- metadata.gz: 3533f42a47a75ae9f5dee05100e8a8b1594e9ac9f2dd5aeb926071a339fc7cbad82c0faa32e724924dd4e16e3c6d4465864e6c3560f042fa25bbb937d3ca80f9
7
- data.tar.gz: fd0423876c4ded5577f0e8ced346a61520ac9df7f1d18b88dadfa3ef59f057a7d2a6ece5c9de67f5ef7b25a73e32edc479a45498a38ac7e742bbb155d7dc55de
6
+ metadata.gz: c6705c471563eede40e9dd71aa133dc3e5adf9a2f014864c44312aab6a3235bd335648b2dc9a40f6d3d1a339ea50258cfe2c31f56d61f617f67dba5be4237379
7
+ data.tar.gz: 9268dc3c81722d2e42824a3e6ac175e7c12e4927254fcdb7f95825f3797b060e2c912ba62af4517841c4f076cd3379ee4be48c44e866796037fb7cb27ad2520c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -7,25 +7,29 @@ require 'dynarex'
7
7
 
8
8
  class DxTitleSearch
9
9
 
10
- def initialize(obj, debug: false)
10
+ def initialize(obj=nil, sources: nil, debug: false)
11
11
 
12
12
  @debug = debug
13
13
 
14
- # is it a Dynarex file location?
15
- s = if obj.lines.length < 2 then
16
-
17
- xml = RXFHelper.read(obj).first
18
-
19
- dx = Dynarex.new(xml)
20
-
21
- dx.all.map do |x|
22
- "%d %s %s" % [Time.parse(x.created).to_i, x.title, x.url]
23
- end.join("\n")
24
-
25
- else
26
- obj
14
+ s = if sources then
15
+
16
+ dx = Dynarex.new(sources)
17
+ dx.all.map {|x| read x.uri }.join
18
+
19
+ elsif obj then
20
+
21
+ # is it a Dynarex file location?
22
+ if obj.lines.length < 2 then
23
+
24
+ read obj
25
+
26
+ else
27
+
28
+ obj
29
+
30
+ end
27
31
  end
28
-
32
+
29
33
  @h = h = s.lines.inject({}) do |r,x|
30
34
  key, value = x.split(/\s+(?=[^\s]+$)/,2)
31
35
  r.merge(key.rstrip => value)
@@ -36,21 +40,34 @@ class DxTitleSearch
36
40
  end
37
41
 
38
42
  def search(keywords)
43
+
44
+ phrases = @a.grep /#{keywords}/i
39
45
 
40
46
  # find out the keywords count for each entry found
41
- a = keywords.split.flat_map {|x| @a.grep /#{x}/i }.uniq.map do |entry|
47
+ a0 = keywords.split.flat_map do |x|
48
+ next if @a.length < 2
49
+ @a.grep /#{x}/i
50
+ end
51
+
52
+ a = a0.uniq.map do |entry|
42
53
  [entry, entry.scan(/#{keywords.split.join('|')}/).uniq.count]
43
54
  end
44
55
 
45
56
  # sort by keywords found per entry and then date
57
+ #a2 = (phrases + a).uniq.sort do |x, x2|
46
58
  a2 = a.sort do |x, x2|
47
59
  -([x.last, x.first[/^\d+/], ] <=> [x2.last, x2.first[/^\d+/]])
48
60
  end
49
61
 
50
62
  # format each result as a Hash object
51
- a3 = a2.map do |x|
52
-
53
- line, _ = x
63
+ a3 = (phrases + a2).map do |x|
64
+
65
+ if x.length > 1 then
66
+ line, _ = x
67
+ else
68
+ line = x
69
+ end
70
+
54
71
  puts 'line: ' + line.inspect if @debug
55
72
 
56
73
  rawtime, title = line.split(/ +/,2)
@@ -65,6 +82,17 @@ class DxTitleSearch
65
82
  return a3
66
83
 
67
84
  end
85
+
86
+ private
87
+
88
+ def read(source)
68
89
 
69
- end
90
+ dx = Dynarex.new(source)
70
91
 
92
+ dx.all.map do |x|
93
+ "%d %s %s" % [Time.parse(x.created).to_i, x.title, x.url]
94
+ end.join("\n")
95
+
96
+ end
97
+
98
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dxtitle_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ODgOmcgAsTin0T9l0vWQJnj2OClh1pcC6tFnQXXcYuwTpbtM2v4OmUfUDvJmwQ42
36
36
  POydZUYZg49X9TlTDqPMKed0
37
37
  -----END CERTIFICATE-----
38
- date: 2019-07-23 00:00:00.000000000 Z
38
+ date: 2019-08-07 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: dynarex
metadata.gz.sig CHANGED
Binary file