separa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58c1213d2bc5d1b3ff0d372415ad41b0d1be447d
4
+ data.tar.gz: cf736b30c7478dd3b90dd3583ea114545b0e4953
5
+ SHA512:
6
+ metadata.gz: e0fc3323895152e27e1256fa5e774d8871b4d2b9dd4cc793777149eba591c02de0fae7dc3e51dee94535565f5e5fa413595d8195b52abfe4d6ccdde8171067f4
7
+ data.tar.gz: 8b83a6547788a2f517db85de1242181f3ce72712f8fb7e17b230688266069bce5eefa8f5092d401cce3af5d8fc87b955dc6e70393cff11e0dd545871cc69d456
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .idea/
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Julián Porta
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ Separa
2
+ ====
3
+
4
+ Separa splits chunks of text into tokens to be indexed
5
+
6
+ Description
7
+ -----------
8
+
9
+ Separa splits chunks of text or ruby objects into tokens to be indexed by [Busca](https://github.com/Porta/busca), the simple redis search
10
+
11
+ ## Installation
12
+
13
+ As usual, you can install it using rubygems.
14
+
15
+ ```
16
+ $ gem install separa
17
+ ```
18
+
19
+ ## Usage
20
+
data/lib/Separa/obj.rb ADDED
@@ -0,0 +1,15 @@
1
+ class Separa
2
+ module Obj
3
+
4
+ def self.call(text, opts)
5
+ divider = opts[:divider] || ':'
6
+ res = wonderflat(text)
7
+ res.map{|k, v| "#{k.to_s}#{divider}#{v.to_s}"}
8
+ end
9
+
10
+ def self.wonderflat(hash, k = [])
11
+ return {k.join('.') => hash} unless hash.is_a?(Hash)
12
+ hash.inject({}){ |h, v| h.merge! self.wonderflat(v[-1], k + [v[0]]) }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ class Separa
2
+ module Text
3
+ require 'pry'
4
+ def self.call(text, opts)
5
+ regexp = opts[:regexp] || /\W/
6
+ text.split(regexp)
7
+ end
8
+ end
9
+ end
data/lib/separa.rb ADDED
@@ -0,0 +1,22 @@
1
+ class Separa
2
+
3
+ Dir[File.dirname(__FILE__) + '/Separa/*.rb'].each {|file| require file }
4
+
5
+ attr_reader :separador
6
+
7
+ def initialize(separador = Separa::Text, opts = {})
8
+ if separador.respond_to?(:call)
9
+ @separador = separador
10
+ @opts = opts
11
+ else
12
+ @separador = Separa::Text
13
+ @opts = separador
14
+ end
15
+ end
16
+
17
+ def call(words)
18
+ @separador.call(words, @opts)
19
+ end
20
+
21
+
22
+ end
data/makefile ADDED
@@ -0,0 +1,2 @@
1
+ test:
2
+ cutest ./tests/*_test.rb
data/separa.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "separa"
5
+ s.version = "0.0.1"
6
+ s.summary = "Separa splits chunks of text into tokens to be indexed"
7
+ s.description = "Separa splits chunks of text into tokens to be indexed by Busca, the simple redis search"
8
+ s.authors = ["Julián Porta"]
9
+ s.email = ["julian@porta.sh"]
10
+ s.homepage = "http://github.com/Porta/separa"
11
+ s.files = `git ls-files`.split("\n")
12
+ s.license = "MIT"
13
+ s.add_development_dependency "cutest", '~>1.2'
14
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path("../lib/separa", File.dirname(__FILE__))
2
+
3
+
4
+ setup do
5
+
6
+ end
7
+
8
+ test "default separator should be text" do
9
+ sep = Separa.new()
10
+ assert_equal sep.separador, Separa::Text
11
+ end
12
+
13
+ test "Separa::Text should separate words" do
14
+ sep = Separa.new()
15
+ words = "words are something we use"
16
+ result = sep.call(words)
17
+ assert_equal result, %w(words are something we use)
18
+ end
19
+
20
+ test "Separa::Text should accept a regexp" do
21
+ sep = Separa.new(regexp: /\s/)
22
+ words = "words are something we use"
23
+ result = sep.call(words)
24
+ assert_equal result, %w(words are something we use)
25
+ end
26
+
27
+
28
+ test "Separa::Text should separate words using another regexp" do
29
+ sep = Separa.new(Separa::Text, regexp: /,/)
30
+ words = "words are something, we use"
31
+ result = sep.call(words)
32
+ assert_equal result, ['words are something',' we use']
33
+ end
34
+
35
+ test "Separa::Text should return an one element array if no split is done" do
36
+ sep = Separa.new(regexp: /,/)
37
+ words = "this is hardcore"
38
+ result = sep.call(words)
39
+ assert_equal result, ['this is hardcore']
40
+ end
41
+
42
+ test "Separa::Obj should be loaded" do
43
+ sep = Separa.new(Separa::Obj)
44
+ assert_equal sep.separador, Separa::Obj
45
+ end
46
+
47
+ test "Separa::Obj should separate Obj into key:value pairs" do
48
+ sep = Separa.new(Separa::Obj)
49
+ h = { uno: 1, dos: 2, tres: {uno: 'one', dos: 'two'} }
50
+ result = sep.call(h)
51
+ assert_equal result, ['uno:1', 'dos:2', 'tres.uno:one', 'tres.dos:two']
52
+ end
53
+
54
+ test "Separa::Obj should separate Obj into key.value pairs" do
55
+ sep = Separa.new(Separa::Obj, divider: '.')
56
+ h = { uno: 1, dos: 2, tres: {uno: 'one', dos: 'two'} }
57
+ result = sep.call(h)
58
+ assert_equal result, ['uno.1', 'dos.2', 'tres.uno.one', 'tres.dos.two']
59
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: separa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julián Porta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cutest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ description: Separa splits chunks of text into tokens to be indexed by Busca, the
28
+ simple redis search
29
+ email:
30
+ - julian@porta.sh
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - LICENSE
37
+ - README.md
38
+ - lib/Separa/obj.rb
39
+ - lib/Separa/text.rb
40
+ - lib/separa.rb
41
+ - makefile
42
+ - separa.gemspec
43
+ - tests/separa_test.rb
44
+ homepage: http://github.com/Porta/separa
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.6
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Separa splits chunks of text into tokens to be indexed
68
+ test_files: []