word_mix 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in word_mix.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ word_mix (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.11.0)
11
+ rspec-core (~> 2.11.0)
12
+ rspec-expectations (~> 2.11.0)
13
+ rspec-mocks (~> 2.11.0)
14
+ rspec-core (2.11.1)
15
+ rspec-expectations (2.11.3)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.11.2)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rspec
24
+ word_mix!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 sparkplug
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,78 @@
1
+ # WORD_MIX
2
+
3
+ PLEASE WATCH WORD_MIX-0.0.7 FOR THE TEST (see details in NOTES...)
4
+
5
+ combine 2 small word to get a word of (N) characters:
6
+
7
+ al + bums => albums
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'word_mix'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install word_mix
22
+
23
+ ## Usage
24
+
25
+ Rake task:
26
+
27
+ rake word_mix:convert
28
+
29
+ Specify a single file path ( default = Rails.root + "/wordlist.txt"):
30
+
31
+ rake word_mix:convert TARGET="/complete/path/to/file"
32
+
33
+ Specify a custom amount of letter (default = 6):
34
+
35
+ rake word_mix:convert AMOUNT=6
36
+
37
+ Specify separator to use a custom splitting pattern ( default = "\n" ):
38
+
39
+ rake word_mix:convert SEPARATOR="\n"
40
+
41
+ Specify case_insensitive:
42
+
43
+ rake word_mix:convert CASE_INSENSITIVE="true"
44
+
45
+ You can pass more than one option
46
+
47
+ ## NOTES
48
+
49
+ VERSION 0.0.7 ...
50
+
51
+ KATA release after 2:30 h
52
+
53
+
54
+
55
+ I saw an unexpected amount of download so I'm tuning the gem a bit :D
56
+
57
+ VERSION 0.0.8 ...
58
+
59
+ new AMOUNT feature
60
+
61
+ VERSION 0.0.9
62
+
63
+ optimize the code by using hash instead of array
64
+ fix test
65
+
66
+ VERSION 0.1.0
67
+
68
+ remove unused file and add correction to README.md
69
+
70
+ VERSION 1.1.0
71
+
72
+ refactor + add exception
73
+
74
+
75
+ You could experiment permission issue if not used properly
76
+
77
+ Go see hash_rocket gem to see more flexibility using regex:
78
+ https://github.com/4nkh/hash_rocket
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/answer.txt ADDED
@@ -0,0 +1,8 @@
1
+ al + bums => albums
2
+ bar + ely => barely
3
+ be + foul => befoul
4
+ con + vex => convex
5
+ here + by => hereby
6
+ jig + saw => jigsaw
7
+ tail + or => tailor
8
+ we + aver => weaver
@@ -0,0 +1,7 @@
1
+ namespace "word_mix" do
2
+
3
+ desc "combine 2 small word to get a 6 letters word"
4
+ task convert: :environment do
5
+ WordMix.init
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require "word_mix"
2
+
3
+ module WordMix
4
+ if defined? Rails::Railtie
5
+ require "rails"
6
+ class Railtie < Rails::Railtie
7
+ rake_tasks do
8
+ load "tasks/word_mix.rake"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module WordMix
2
+ VERSION = "0.1.2"
3
+ end
data/lib/word_mix.rb ADDED
@@ -0,0 +1,83 @@
1
+ require "word_mix/version"
2
+ require "word_mix/railtie" if defined?(Rails)
3
+ module WordMix
4
+ class AmountError < Exception
5
+ def self.too_small
6
+ puts "Amount should be higher then 1"
7
+ end
8
+ end
9
+
10
+ def self.init
11
+ begin
12
+ set_variables
13
+ build_list
14
+ mix_words
15
+ complete
16
+ rescue AmountError
17
+ AmountError.too_small
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def self.build_list
24
+ list = File.read(@file).split(@separator)
25
+ list.uniq.each do |word|
26
+ @data[word.size][word] = nil if word.size < @amount and word.size != 0
27
+ @data[@amount] << word if word.size == @amount
28
+ end
29
+ end
30
+
31
+ def self.mix_words
32
+ @data.last.each do |word|
33
+ big = @amount-2
34
+ (0..big).each do |i|
35
+ populate_result( word[0..i],
36
+ word[i+1..big+1],
37
+ @data[i+1],
38
+ @data[big+1 - i] ) unless i == @amount or (@data[i+1] == {} or !@data[big+1 - i] == {})
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.populate_result(first, second, match_one, match_two)
44
+ word = first + second
45
+ if @case_insensitive
46
+ word_one = nil
47
+ word_two = nil
48
+ match_one.any?{ |s| s[0].downcase == first.downcase ? word_one = s[0] : nil }
49
+ match_two.any?{ |s| s[0].downcase == second.downcase ? word_two = s[0] : nil }
50
+ @result << "#{word_one} + #{word_two} => #{word}\n" if word_one and word_two
51
+ else
52
+ @result << "#{first} + #{second} => #{word}\n" if match_one.has_key? first and match_two.has_key? second
53
+ end
54
+ end
55
+
56
+ def self.set_data
57
+ (0..@amount).each do |size|
58
+ @data << {} if size != @amount
59
+ @data << [] if size == @amount
60
+ end
61
+ end
62
+
63
+ def self.set_variables
64
+ @start = Time.now
65
+ @data = []
66
+ @result = []
67
+ @root = File.expand_path('../..',__FILE__)
68
+ @root = Rails.root.to_s if defined?(Rails)
69
+ @file = ENV["TARGET"] ? ENV["TARGET"] : @root + "/wordlist.txt"
70
+ @case_insensitive = ENV["CASE_INSENSITIVE"]
71
+ @amount = ENV["AMOUNT"] ? ENV["AMOUNT"].to_i : 6
72
+ raise AmountError if @amount < 2
73
+ @separator = ENV["SEPARATOR"] ? ENV["SEPARATOR"] : "\n"
74
+ set_data
75
+ end
76
+
77
+ def self.complete
78
+ File.open(@root + "/answer.txt", "w") { |file| file.puts @result.join }
79
+ puts "#{@result.size} results found"
80
+ puts "It took only #{Time.now - @start} seconds to complete the process"
81
+ end
82
+ private_class_method :build_list, :mix_words, :populate_result, :set_data, :set_variables, :complete
83
+ end
@@ -0,0 +1,9 @@
1
+ ha
2
+ sh
3
+ hash
4
+ al
5
+ lo
6
+ allo
7
+ za
8
+ zoo
9
+ zazoo
@@ -0,0 +1,2 @@
1
+ ha + sh => hash
2
+ al + lo => allo
@@ -0,0 +1,87 @@
1
+ al
2
+
3
+
4
+ bums
5
+
6
+
7
+ albums
8
+
9
+
10
+ bar
11
+
12
+
13
+ ely
14
+
15
+
16
+ barely
17
+
18
+
19
+ be
20
+
21
+
22
+ foul
23
+
24
+
25
+ befoul
26
+
27
+
28
+ con
29
+
30
+
31
+ vex
32
+
33
+
34
+ convex
35
+
36
+
37
+ here
38
+
39
+
40
+ by
41
+
42
+
43
+ hereby
44
+
45
+
46
+ jig
47
+
48
+
49
+ saw
50
+
51
+
52
+ jigsaw
53
+
54
+
55
+ tail
56
+
57
+
58
+ or
59
+
60
+
61
+ tailor
62
+
63
+
64
+ we
65
+
66
+
67
+ aver
68
+
69
+
70
+ weaver
71
+
72
+
73
+ Jig
74
+
75
+
76
+ SAW
77
+
78
+
79
+ Pou
80
+
81
+
82
+ Let
83
+
84
+
85
+ poulet
86
+
87
+
@@ -0,0 +1,9 @@
1
+ al + bums => albums
2
+ bar + ely => barely
3
+ be + foul => befoul
4
+ con + vex => convex
5
+ here + by => hereby
6
+ jig + saw => jigsaw
7
+ tail + or => tailor
8
+ we + aver => weaver
9
+ Pou + Let => poulet
@@ -0,0 +1,22 @@
1
+ al
2
+
3
+
4
+ bum
5
+
6
+
7
+ roger
8
+
9
+
10
+ ca
11
+
12
+
13
+ ne
14
+
15
+
16
+ fite
17
+
18
+
19
+ pas
20
+
21
+
22
+ lettre
@@ -0,0 +1 @@
1
+ al,bums,albums,off,end,offend
@@ -0,0 +1,2 @@
1
+ al + bums => albums
2
+ off + end => offend
@@ -0,0 +1,78 @@
1
+ al
2
+
3
+
4
+ bums
5
+
6
+
7
+ al
8
+
9
+
10
+ bums
11
+
12
+
13
+ albums
14
+
15
+
16
+ bar
17
+
18
+
19
+ ely
20
+
21
+
22
+ barely
23
+
24
+
25
+ be
26
+
27
+
28
+ foul
29
+
30
+
31
+ befoul
32
+
33
+
34
+ con
35
+
36
+
37
+ vex
38
+
39
+
40
+ convex
41
+
42
+
43
+ here
44
+
45
+
46
+ by
47
+
48
+
49
+ hereby
50
+
51
+
52
+ jig
53
+
54
+
55
+ saw
56
+
57
+
58
+ jigsaw
59
+
60
+
61
+ tail
62
+
63
+
64
+ or
65
+
66
+
67
+ tailor
68
+
69
+
70
+ we
71
+
72
+
73
+ aver
74
+
75
+
76
+ weaver
77
+
78
+
@@ -0,0 +1,8 @@
1
+ al + bums => albums
2
+ bar + ely => barely
3
+ be + foul => befoul
4
+ con + vex => convex
5
+ here + by => hereby
6
+ jig + saw => jigsaw
7
+ tail + or => tailor
8
+ we + aver => weaver