flisol_sort 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/flisol_sort.gemspec +24 -0
- data/lib/flisol_sort.rb +9 -0
- data/lib/flisol_sort/loader.rb +30 -0
- data/lib/flisol_sort/sorteador.rb +13 -0
- data/lib/flisol_sort/version.rb +3 -0
- data/spec/lib/flisol_sort/loader_spec.rb +12 -0
- data/spec/lib/flisol_sort/sorteador_spec.rb +35 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/fixtures/participants.csv +2 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a7d370378d6a52f5eaadf9a742efdcf934e28fb7
|
4
|
+
data.tar.gz: dc7f083a4c1e5056bf36dd7ba5ce22c51610a345
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4473c7c395c454469214bfea231ac366c8b638c6d86dbe2f7e77756541b1b148af7e4f65a35389f4690f45706476454e32862ac3570ffc40619f641d527747bf
|
7
|
+
data.tar.gz: d8e05e6ffc52b39914380cf598669045354d2ed4ce4b5356bb57242ee45edd08179efbb250d4d2edea1fb8780303d3bca6f05b990a5dcb40c44f1a2fe66780c3
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format doc
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brenno Costa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# FlisolSort
|
2
|
+
|
3
|
+
Participant random picker for give aways.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'flisol_sort'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install flisol_sort
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'flisol_sort'
|
23
|
+
|
24
|
+
sorter = FlisolSort::Sorteador.new '/Users/brennovich/Desktop/participants.csv', ['Nome', 'Sobrenome']
|
25
|
+
sorter.lucky_guy
|
26
|
+
# => {:nome=>"Mr. Potato", :sobrenome=>"Cocada"}
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/flisol_sort.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flisol_sort/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flisol_sort"
|
8
|
+
spec.version = FlisolSort::VERSION
|
9
|
+
spec.authors = ["Brenno Costa", "Halan Pinheiro"]
|
10
|
+
spec.email = ["brennolncosta@gmail.com"]
|
11
|
+
spec.description = %q{Participant random picker for give aways}
|
12
|
+
spec.summary = %q{Give away without problems}
|
13
|
+
spec.homepage = "https://github.com/brennovich/flisol_sort"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/lib/flisol_sort.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class FlisolSort::Loader
|
2
|
+
def initialize file, columns
|
3
|
+
@file = file
|
4
|
+
@columns = columns
|
5
|
+
end
|
6
|
+
|
7
|
+
def load
|
8
|
+
participants = []
|
9
|
+
|
10
|
+
CSV.foreach @file, :headers => true do |row|
|
11
|
+
participants << self.class.row_to_hash(row, @columns)
|
12
|
+
end
|
13
|
+
|
14
|
+
participants
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.row_to_hash row, columns
|
20
|
+
participant = {}
|
21
|
+
columns.each do |col|
|
22
|
+
participant[header_converter(col)] = row[col]
|
23
|
+
end
|
24
|
+
participant
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.header_converter header
|
28
|
+
header.downcase.split(' ').join('_').to_sym
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FlisolSort::Loader do
|
4
|
+
subject(:loader) { described_class.new "#{FIXTURE_PATH}/participants.csv", ['Nome']}
|
5
|
+
|
6
|
+
describe '#load' do
|
7
|
+
it 'returns an array of participants' do
|
8
|
+
participants = loader.load
|
9
|
+
expect(participants).to eql [{:nome => 'Mr.Potato'}]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FlisolSort::Sorteador do
|
4
|
+
subject(:sorteador) { described_class.new file, columns, loader }
|
5
|
+
|
6
|
+
let(:loader) { mock FlisolSort::Loader }
|
7
|
+
let(:file) { "#{FIXTURE_PATH}/participants.csv" }
|
8
|
+
let(:columns) { ['Nome'] }
|
9
|
+
|
10
|
+
it 'instanciates a loader to read CSV file' do
|
11
|
+
loader.should_receive(:new).with(file, columns)
|
12
|
+
sorteador
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#participants' do
|
16
|
+
before { loader.stub(:new).with(file, columns).and_return(loader) }
|
17
|
+
|
18
|
+
it 'calls loader' do
|
19
|
+
loader.should_receive(:load)
|
20
|
+
sorteador.participants
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#lucky_guy' do
|
25
|
+
let(:participants) { double ['participant']}
|
26
|
+
|
27
|
+
before { loader.stub(:new).with(file, columns).and_return(loader) }
|
28
|
+
|
29
|
+
it 'returns a sample from participants' do
|
30
|
+
loader.should_receive(:load).and_return(participants)
|
31
|
+
participants.should_receive(:sample).and_return('participant')
|
32
|
+
sorteador.lucky_guy
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative '../lib/flisol_sort'
|
2
|
+
|
3
|
+
FIXTURE_PATH = "#{File.dirname(__FILE__)}/support/fixtures"
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
7
|
+
config.run_all_when_everything_filtered = true
|
8
|
+
config.order = 'random'
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flisol_sort
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brenno Costa
|
8
|
+
- Halan Pinheiro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Participant random picker for give aways
|
57
|
+
email:
|
58
|
+
- brennolncosta@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- flisol_sort.gemspec
|
70
|
+
- lib/flisol_sort.rb
|
71
|
+
- lib/flisol_sort/loader.rb
|
72
|
+
- lib/flisol_sort/sorteador.rb
|
73
|
+
- lib/flisol_sort/version.rb
|
74
|
+
- spec/lib/flisol_sort/loader_spec.rb
|
75
|
+
- spec/lib/flisol_sort/sorteador_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/support/fixtures/participants.csv
|
78
|
+
homepage: https://github.com/brennovich/flisol_sort
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.0.0
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Give away without problems
|
102
|
+
test_files:
|
103
|
+
- spec/lib/flisol_sort/loader_spec.rb
|
104
|
+
- spec/lib/flisol_sort/sorteador_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/support/fixtures/participants.csv
|