briskly 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df7110ca2e129d80ed1fddff2ddac4586df49e40
4
- data.tar.gz: 0a24ed790f82bef7d4f846d3c48e624e4b0d23d7
3
+ metadata.gz: e0dc8ff652c0cb51e60994b1016a2d4ea35aa347
4
+ data.tar.gz: dcacee83e5e31a9c75f19d18a55d5a6ff0e27ea4
5
5
  SHA512:
6
- metadata.gz: f1e85a6d1d326a130608a6b746dd02045daa334ff45e1b48b741ccaf5f29d77f5c9aeb57526b4d657de9c9f325b9294843e8b3344868d4ca078a2f17842d0c61
7
- data.tar.gz: cec814dc4603b6820395e4da94c611352d8a55e4ec3ff22e7195db58ab315ac67163d8a441cfaf88b29bb41b1a49f83a3a353beb652dca3206445dbf5b0ab197
6
+ metadata.gz: 041ac018970ffbdf3e17803689b3b13fca2ebbbcc9398caa26b5ccf9766fceb0afcc34532d61acf283b7b68a4ee3d1fe6f3a95cbbbf83f54252ac8ccfce227a3
7
+ data.tar.gz: 8de4b98090ffcafa652996d97927d36198fc3e246573f4f77ef451bdc6987511426de07747c113ca7addeeed49a8e8526c511ac9b9908345c4f79ad6e5d3cce0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- briskly (0.1.3)
4
+ briskly (0.1.4)
5
5
  fast_trie
6
6
  i18n
7
7
 
data/README.md CHANGED
@@ -41,14 +41,9 @@ result
41
41
  result['cities'].first.keyword
42
42
  => 'London'
43
43
 
44
-
45
44
  result = Briskly.on('cities').search('londres')
46
45
  result['cities'].first.keyword
47
46
  => 'Londres'
48
-
49
- result['cities'].first.alternatives
50
- => ['London']
51
-
52
47
  ```
53
48
 
54
49
  Example with multiple collections
@@ -5,14 +5,12 @@ class Briskly::Element
5
5
 
6
6
  attr_reader :data
7
7
  attr_reader :keyword
8
- attr_reader :alternatives
9
8
 
10
- def initialize(keyword, data = nil, alternatives = [])
9
+ def initialize(keyword, data = nil)
11
10
  raise ArgumentError unless keyword
12
11
 
13
12
  @keyword = Briskly::Keyword.new(keyword)
14
13
  @data = data
15
- @alternatives = alternatives.map { |alternative| Briskly::Keyword.new(alternative) }
16
14
  end
17
15
 
18
16
  def keyword(internal = nil)
@@ -4,20 +4,44 @@ require 'i18n'
4
4
  class Briskly::Keyword
5
5
 
6
6
  def initialize(keyword)
7
- @keyword = keyword
7
+ @keyword = FrozenString.get(keyword)
8
8
  end
9
9
 
10
10
  def to_s
11
- @keyword
11
+ @keyword.to_s
12
12
  end
13
13
 
14
14
  def normalised
15
15
  @_normalised ||= begin
16
- I18n.transliterate(@keyword)
16
+ I18n.transliterate(to_s)
17
17
  .downcase
18
18
  .gsub(/[^a-z -]/, '')
19
19
  .gsub(/[\s-]+/, ' ')
20
20
  end
21
21
  end
22
22
 
23
+ class FrozenString
24
+ module ClassMethods
25
+ def get(string)
26
+ @@repository ||= {}
27
+ @@repository[string.freeze] ||= new(string.freeze)
28
+ end
29
+ end
30
+ extend ClassMethods
31
+
32
+ def initialize(string)
33
+ @value = string
34
+ end
35
+
36
+ def to_str
37
+ @value
38
+ end
39
+
40
+ alias_method :to_s, :to_str
41
+
42
+ class << self
43
+ private :new
44
+ end
45
+ end
46
+
23
47
  end
@@ -21,8 +21,7 @@ class Briskly::Store
21
21
  keywords = Array.new(1) { value[:keyword] }.flatten(1)
22
22
 
23
23
  keywords.each do |keyword|
24
- alternatives = keywords - [ keyword ]
25
- element = Briskly::Element.new(keyword, value[:data], alternatives)
24
+ element = Briskly::Element.new(keyword, value[:data])
26
25
  normalised = element.keyword(:internal).normalised
27
26
 
28
27
  # We need to make sure we keep the index
@@ -1,6 +1,6 @@
1
1
  require 'pathname'
2
2
 
3
3
  module Briskly
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  GEMDIR = Pathname.new(__FILE__).parent.parent.parent
6
6
  end
@@ -27,14 +27,6 @@ describe Briskly::Element do
27
27
 
28
28
  end
29
29
 
30
- context 'alternatives' do
31
- subject { described_class.new('foo', { a: 2 }, ['bar', 'bear']) }
32
-
33
- it 'converts alternatives to keyword elements' do
34
- expect(subject.alternatives.first.to_s).to eql('bar')
35
- end
36
- end
37
-
38
30
  context 'without keywords' do
39
31
  it 'raises ArgumentError' do
40
32
  expect { described_class.new }.to raise_error(ArgumentError)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: briskly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Cunha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n