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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +0 -5
- data/lib/briskly/element.rb +1 -3
- data/lib/briskly/keyword.rb +27 -3
- data/lib/briskly/store.rb +1 -2
- data/lib/briskly/version.rb +1 -1
- data/spec/briskly/element_spec.rb +0 -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: e0dc8ff652c0cb51e60994b1016a2d4ea35aa347
|
4
|
+
data.tar.gz: dcacee83e5e31a9c75f19d18a55d5a6ff0e27ea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 041ac018970ffbdf3e17803689b3b13fca2ebbbcc9398caa26b5ccf9766fceb0afcc34532d61acf283b7b68a4ee3d1fe6f3a95cbbbf83f54252ac8ccfce227a3
|
7
|
+
data.tar.gz: 8de4b98090ffcafa652996d97927d36198fc3e246573f4f77ef451bdc6987511426de07747c113ca7addeeed49a8e8526c511ac9b9908345c4f79ad6e5d3cce0
|
data/Gemfile.lock
CHANGED
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
|
data/lib/briskly/element.rb
CHANGED
@@ -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
|
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)
|
data/lib/briskly/keyword.rb
CHANGED
@@ -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(
|
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
|
data/lib/briskly/store.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/briskly/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|