fluorescent 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fluorescent.rb +16 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03dc27f7c7d0367364e792d9925252e2a88eb70e
|
4
|
+
data.tar.gz: 1d610f34457341e691341f86ada587e4d53a47a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 384341b2f3babe45846e912a420aff68609012f4ac6a64b6d7ae8c518d98e68ed1565317486dbc8c8472abf4d633617408fc4da23a53472585c0ed70e8a28dc2
|
7
|
+
data.tar.gz: ac02d9f67de10301c3120ded474ba3286d5bb2841cbcdb6d28b54634d1fd65c503cecf8caa73b7e02bef8793e20c71d22b7d85cc77552cded341acc56908765a
|
data/lib/fluorescent.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
1
3
|
class Fluorescent
|
2
|
-
|
4
|
+
attr_accessor :columns, :to_filter, :results, :terms, :padding, :formatted_results, :id_column
|
3
5
|
def initialize args
|
4
6
|
# number of characters to display before/after search terms
|
5
7
|
# example:
|
@@ -9,6 +11,7 @@ class Fluorescent
|
|
9
11
|
# padded display: "...t do you think this is a test..."
|
10
12
|
@padding = 10
|
11
13
|
@formatted_results = []
|
14
|
+
@id_column = "id"
|
12
15
|
args.each do |k,v|
|
13
16
|
instance_variable_set("@#{k}", v) unless v.nil?
|
14
17
|
end
|
@@ -24,16 +27,22 @@ class Fluorescent
|
|
24
27
|
# 2. replace the search terms in the results with bold text
|
25
28
|
# index starting at the first character of the search terms
|
26
29
|
# to the length of the search terms + the padding config value
|
27
|
-
|
30
|
+
string = r.send(c).to_s
|
28
31
|
row[c] = highlight string # need to find a better way to do this
|
29
32
|
if @to_filter.include? c
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
# account for things like one word search terms
|
34
|
+
# or if the padding length is longer than the search term string
|
35
|
+
if @terms.length <= @padding
|
36
|
+
row[c] = highlight @terms
|
37
|
+
else
|
38
|
+
row[c] = highlight string[
|
39
|
+
string.index(@terms[0]),
|
40
|
+
string.index(@terms[0]) + @terms.length + @padding
|
41
|
+
] << "..."
|
42
|
+
end
|
34
43
|
end
|
35
44
|
end
|
36
|
-
@formatted_results.push({:id =>r.
|
45
|
+
@formatted_results.push({:id =>r.send(@id_column)}.merge(row))
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
@@ -46,5 +55,4 @@ class Fluorescent
|
|
46
55
|
distill
|
47
56
|
@formatted_results
|
48
57
|
end
|
49
|
-
|
50
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluorescent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devin Austin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Highlight search terms in a result set and distill the result text down
|
14
14
|
to the pertinent parts
|