fluorescent 0.0.0 → 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fluorescent.rb +16 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72c5cd15896224a1cf0a08effeb7832f9aae0b11
4
- data.tar.gz: ca91915607c6f19ffa9725c3927c62dca97f1fc2
3
+ metadata.gz: 03dc27f7c7d0367364e792d9925252e2a88eb70e
4
+ data.tar.gz: 1d610f34457341e691341f86ada587e4d53a47a2
5
5
  SHA512:
6
- metadata.gz: e39e92d3017940e327038eb06b20f6eec874b77fcc0dda85410d95b9d16b47d1689052faca9bf6b770c444e198f76b64d6046484bc3e4de33eecd779e0b32ccf
7
- data.tar.gz: 1d6b9592d8b14f3bc1fdcc1c011b168dca0f83b1c5a0423cfb63aa2128b50fbc3c73c3fdb35c6148e58500b68915cf11522d9ed52cac17ed57c13a153f3a3462
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
- attr_reader :columns, :to_filter
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
- string = r.send(c).to_s
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
- row[c] = highlight string[
31
- string.index(@terms[0]),
32
- string.index(@terms[0]) + @terms.length + @padding
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.id}.merge(row))
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.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-03-09 00:00:00.000000000 Z
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