saltine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ .bundle/
2
+ *.gem
3
+ Gemfile.lock
4
+ pkg/
5
+ coverage/
6
+ *.swp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ unless ENV['COVERAGE'] == 'false'
2
+ require 'simplecov-rcov'
3
+
4
+ class SimpleCov::Formatter::MergedFormatter
5
+ def format(result)
6
+ SimpleCov::Formatter::HTMLFormatter.new.format(result)
7
+ SimpleCov::Formatter::RcovFormatter.new.format(result)
8
+ end
9
+ end
10
+
11
+ SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
12
+ end
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in saltine.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Blake Thomas
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ # saltine - add a little salt
2
+
3
+ ## License
4
+ [MIT](http://opensource.org/licenses/MIT). See [LICENSE](LICENSE).
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+ task :default => :spec
7
+
8
+ desc 'Start IRB with preloaded environment'
9
+ task :console do
10
+ exec 'irb', "-I#{File.join(File.dirname(__FILE__), 'lib')}", '-rsaltine'
11
+ end
@@ -0,0 +1,86 @@
1
+ require 'pry'
2
+ require 'prime-numbers'
3
+
4
+ module Saltine
5
+ class Salt
6
+
7
+ attr_accessor :salt, :salted, :unsalted
8
+
9
+ def self.salt(*args)
10
+ new(*args).salt
11
+ end
12
+
13
+ def initialize(*args)
14
+ @salted = []
15
+ @aggressive = false
16
+
17
+ if args.size == 1 && args.first.class <= Hash
18
+ args = args.first
19
+
20
+ @unsalted = args[:unsalted] || args['unsalted']
21
+ @salt = args[:salt] || args['salt']
22
+
23
+ @aggressive = args[:aggressive] || args['aggressive']
24
+ else
25
+ @unsalted = args
26
+ end
27
+
28
+ end
29
+
30
+ def salt
31
+ return @salt unless @salt.nil?
32
+ elements = [unsalted_cast].flatten.map {|a| a.to_a rescue a}.flatten
33
+ numbers = elements.select {|e| e.class <= Fixnum }
34
+ max = numbers.max ** 0.5
35
+ primes = ( max.to_i.downto(2).select { |i| sieve.is_prime?(i) } )
36
+ @salt = primes.any? ? primes[rand(primes.size)] : 997
37
+ end
38
+
39
+ def salted
40
+ return @salted unless @salted.empty?
41
+
42
+ @salted = case unsalted_cast
43
+ when Hash
44
+ @salted = Hash[
45
+ unsalted_cast.map do |key,value|
46
+ [key, partition(value).salted]
47
+ end
48
+ ]
49
+ when Enumerable
50
+ @salted = unsalted_cast.map do |uns|
51
+ partition(uns).salted
52
+ end
53
+ else
54
+ @salted = (unsalted_cast.class <= Fixnum) ? unsalted_cast * salt : unsalted_cast
55
+ end
56
+
57
+ @salted
58
+ end
59
+
60
+ def reset
61
+ @salted = []
62
+ @salt = nil
63
+ end
64
+
65
+ def unsalted_cast
66
+ return unsalted unless aggressive?
67
+ @unsalted_cast ||= ( unsalted.respond_to?(:to_i) ? unsalted.to_i : Integer(unsalted) ) rescue unsalted
68
+ end
69
+ private :unsalted_cast
70
+
71
+ def partition(uns)
72
+ self.class.new(:unsalted => uns, :salt => salt, :aggressive => aggressive?)
73
+ end
74
+ private :partition
75
+
76
+ def sieve
77
+ @sieve ||= PrimeNumbers::Generator.new(:sieve_of_eratosthenes)
78
+ end
79
+ private :sieve
80
+
81
+ def aggressive?
82
+ ['true', :true, true].include?(@aggressive)
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module Saltine
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "saltine/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "saltine"
7
+ s.version = Saltine::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Blake Thomas"]
10
+ s.email = ["bwthomas@gmail.com"]
11
+ s.homepage = "https://github.com/bwthomas/saltine"
12
+ s.summary = %q{Add a little salt}
13
+ s.description = %q{Add a little salt}
14
+ s.license = 'MIT'
15
+
16
+ s.rubyforge_project = "saltine"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'prime-numbers'
24
+
25
+ s.add_development_dependency 'rspec', '~>2.6.0'
26
+ s.add_development_dependency 'simplecov'
27
+ s.add_development_dependency 'simplecov-rcov'
28
+ s.add_development_dependency 'rake'
29
+ s.add_development_dependency 'pry'
30
+ end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_filter "vendor"
5
+ add_filter "spec"
6
+ end
7
+
8
+ require File.expand_path("../../lib/saltine", __FILE__)
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saltine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Blake Thomas
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: prime-numbers
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.6.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.6.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov-rcov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Add a little salt
111
+ email:
112
+ - bwthomas@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .simplecov
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE
123
+ - README.md
124
+ - Rakefile
125
+ - lib/saltine.rb
126
+ - lib/saltine/version.rb
127
+ - saltine.gemspec
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/bwthomas/saltine
130
+ licenses:
131
+ - MIT
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project: saltine
150
+ rubygems_version: 1.8.23
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Add a little salt
154
+ test_files:
155
+ - spec/spec_helper.rb
156
+ has_rdoc: