fluorescent 0.0.5 → 0.0.6

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 +25 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18c8a78e868d8e98f41b90aacffb1d8382bc3928
4
- data.tar.gz: 722e204650ee3978f02c2cf1730bee6ad54f9d44
3
+ metadata.gz: 1f6908fe9d74e9c6ff92248c064aaa777e2c6e11
4
+ data.tar.gz: 97960713c3cde86ae2cf5ca31b76834147b94b73
5
5
  SHA512:
6
- metadata.gz: 69a75bdd56007068c5efbfbf003da3320e5e9a4811cddc02e4c185cb4942406d62fa9264eb6d78be9017b3830de119c226c360ff2affba6a029961046d478ab9
7
- data.tar.gz: 571a4f29225c9d847ef43ccd82db8a244765bc83662df9d0d647b1f723584136075751de6320c43c4ecbd2b76152d67868570a4429c15c201d97d6b3f391c158
6
+ metadata.gz: eef1ea24dfbed1ad5ff5c62e5ee1c240d9cf6adf6e01107a25d393c8275abd54e8124b299355da0512114ff594319685b25c8062e12983990ad0326388b49506
7
+ data.tar.gz: a9f0a1e5a7f8f53ea87de472e016200726d74de404dc1223cf4d8c94632d20c67b8c6e647ae338300322d0a82024a2451bbc9d36dae8f048f8d37cfdf66cb1f2
@@ -17,15 +17,21 @@ class Fluorescent
17
17
  end
18
18
  end
19
19
 
20
+ def column_names_to_h r
21
+ row = {}
22
+ # make sure we get the rest of the column names in the hash
23
+ r.class.column_names.each do |c|
24
+ row[c] = r.send(c)
25
+ end
26
+ row
27
+ end
28
+
20
29
  # distill search result down to n characters before and after
21
30
  # search terms
22
31
  def distill
23
32
  @results.each do |r|
24
- row = {}
25
- # make sure we get the rest of the column names in the hash
26
- r.class.column_names.each do |c|
27
- row[c] = r.send(c)
28
- end
33
+ row = column_names_to_h(r)
34
+
29
35
  @columns.each do |c|
30
36
  # 1. highlight the search terms
31
37
  # 2. replace the search terms in the results with bold text
@@ -34,16 +40,25 @@ class Fluorescent
34
40
  string = r.send(c).to_s
35
41
  row[c] = highlight string # need to find a better way to do this
36
42
  if @to_filter.include? c
37
- row[c] = highlight string[
38
- string.index(@terms[0]),
39
- string.index(@terms[0]) + @terms.length + @padding
40
- ] << "..."
43
+ # if nothing matches, we don't want to try to highlight
44
+ if string.index(@terms[0]) != nil
45
+ row[c] = highlight string[
46
+ string.index(@terms[0]),
47
+ string.index(@terms[0]) + string.length + @padding
48
+ ] << "..."
49
+ end
41
50
  end
42
51
  end
43
- @formatted_results.push(row)
52
+
53
+ # symbolize hash keys
54
+ @formatted_results.push(symbolize_keys(row))
44
55
  end
45
56
  end
46
57
 
58
+ def symbolize_keys row
59
+ row.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
60
+ end
61
+
47
62
  # highlight the search terms in the result
48
63
  def highlight(string)
49
64
  string.gsub @terms, "<b>#{@terms}</b>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluorescent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devin Austin