nicolus 1.0.0
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.
- data/History.txt +6 -0
- data/Manifest.txt +11 -0
- data/README.txt +50 -0
- data/Rakefile +30 -0
- data/bin/nicolus +1 -0
- data/bin/nicolus.bat +4 -0
- data/lib/nicolus.rb +78 -0
- data/lib/opt_parse.rb +54 -0
- data/test/listes.csv +4 -0
- data/test/listes_3_col.csv +4 -0
- data/test/test_nicolus.rb +56 -0
- metadata +68 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= nicolus
|
2
|
+
http://nicolus.rubyforge.org/
|
3
|
+
by Benjamin Francisoud
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Nicolus is a simple program to make all possible combination out of 2 or more lists of words.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Command line parser
|
12
|
+
* "inverse" generate "aaa 111" and "111 aaa"
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
For example:
|
17
|
+
listA = aaa, bbb, ccc
|
18
|
+
listB = 111, 222
|
19
|
+
|
20
|
+
Combination will be:
|
21
|
+
result= aaa 111, aaa 222, bbb 111, bbb 222, ccc 111, ccc 222
|
22
|
+
|
23
|
+
== INSTALL:
|
24
|
+
|
25
|
+
* gem install nicolus
|
26
|
+
|
27
|
+
== LICENSE:
|
28
|
+
|
29
|
+
(The MIT License)
|
30
|
+
|
31
|
+
Copyright (c) 2008 FIX
|
32
|
+
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
34
|
+
a copy of this software and associated documentation files (the
|
35
|
+
'Software'), to deal in the Software without restriction, including
|
36
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
37
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
38
|
+
permit persons to whom the Software is furnished to do so, subject to
|
39
|
+
the following conditions:
|
40
|
+
|
41
|
+
The above copyright notice and this permission notice shall be
|
42
|
+
included in all copies or substantial portions of the Software.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
45
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
46
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
47
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
48
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
49
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
50
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/nicolus.rb'
|
6
|
+
|
7
|
+
Hoe.new('nicolus', Nicolus::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'nicolus'
|
9
|
+
p.author = 'Benjamin Francisoud'
|
10
|
+
p.email = 'pub.cog@gmail.com'
|
11
|
+
p.summary = 'Nicolus is a simple program to make all possible combination out of 2 or more lists of words.'
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
p.remote_rdoc_dir = '' # Release to root
|
16
|
+
# p.need_zip = true
|
17
|
+
end
|
18
|
+
|
19
|
+
SVN = 'svn+ssh://cogito@rubyforge.org/var/svn/nicolus'
|
20
|
+
|
21
|
+
task :svn_branch => [:clean] do
|
22
|
+
`svn delete #{SVN}/branches/1.X -m "cleanup branch"`
|
23
|
+
`svn copy #{SVN}/trunk #{SVN}/branches/1.X -m "create branch"`
|
24
|
+
end
|
25
|
+
|
26
|
+
task :svn_tag do
|
27
|
+
`svn copy #{SVN}/trunk #{SVN}/tags/#{Nicolus::VERSION} -m "create tag"`
|
28
|
+
end
|
29
|
+
|
30
|
+
# vim: syntax=Ruby
|
data/bin/nicolus
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby ../lib/opt_parse.rb $1 $2 $3 $4 $5 $6 $7 $8 $9
|
data/bin/nicolus.bat
ADDED
data/lib/nicolus.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
|
3
|
+
class Object
|
4
|
+
def blank?
|
5
|
+
respond_to?(:empty?) ? empty? : !self
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class String
|
10
|
+
def unquote!
|
11
|
+
# remove first
|
12
|
+
unless (gsub!(/\A\"/, '').nil?)
|
13
|
+
# remove last
|
14
|
+
gsub!(/\"$/, '')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Nicolus
|
20
|
+
VERSION = '1.0.0'
|
21
|
+
|
22
|
+
class Combinaison
|
23
|
+
def initialize(input_file, filename, inv=false)
|
24
|
+
@input_file, @filename = input_file, filename
|
25
|
+
@inv = inv
|
26
|
+
end
|
27
|
+
|
28
|
+
def inverse?
|
29
|
+
return @inv
|
30
|
+
end
|
31
|
+
|
32
|
+
# a,1,A
|
33
|
+
# b,2,B
|
34
|
+
# c,3,C
|
35
|
+
# => [[a, b, c], [1, 2, 3], [A, B, C]]
|
36
|
+
def create_lists
|
37
|
+
list = []
|
38
|
+
IO.foreach(@input_file) do |line|
|
39
|
+
columns = line.chomp.split(',')
|
40
|
+
list << columns
|
41
|
+
end
|
42
|
+
# [[a, 1, A], [b, 2, B], [c, 3, C]] => [[a, b, c], [1, 2, 3], [A, B, C]]
|
43
|
+
@listes = (Matrix.rows list).transpose.to_a
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_result
|
47
|
+
# Too complex should take a look at ruby 1.9 array.combination()
|
48
|
+
# http://ruby-doc.org/core-1.9/classes/Array.src/M002238.html
|
49
|
+
File.open(@filename, File::CREAT|File::RDWR|File::TRUNC) do |file|
|
50
|
+
@listes.each do |line|
|
51
|
+
line.each do |item|
|
52
|
+
# unless(item.nil? or item.strip.empty?)
|
53
|
+
unless(item.blank?)
|
54
|
+
item.unquote!
|
55
|
+
pos = @listes.index(line)
|
56
|
+
sub_array = @listes - @listes[0, pos+1]
|
57
|
+
sub_array.each do |sub_line|
|
58
|
+
sub_line.each do |rest|
|
59
|
+
# unless(rest.nil? or rest.strip.empty?)
|
60
|
+
unless(rest.blank?)
|
61
|
+
rest.unquote!
|
62
|
+
file << "#{item} #{rest}\n"
|
63
|
+
file << "#{rest} #{item}\n" if(inverse?)
|
64
|
+
end # unless(rest)
|
65
|
+
end # sub_line
|
66
|
+
end # sub_array
|
67
|
+
end # unless(item)
|
68
|
+
end # line.each
|
69
|
+
end # @listes.each
|
70
|
+
end # File.open
|
71
|
+
end # create_result()
|
72
|
+
|
73
|
+
def run
|
74
|
+
create_lists
|
75
|
+
create_result
|
76
|
+
end
|
77
|
+
end # class Combinaison
|
78
|
+
end # module Nicolus
|
data/lib/opt_parse.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require File.dirname(__FILE__) + '/nicolus.rb'
|
3
|
+
|
4
|
+
module Nicolus
|
5
|
+
|
6
|
+
class OptParse
|
7
|
+
# Return a structure describing the options.
|
8
|
+
def self.parse(args)
|
9
|
+
options = {}
|
10
|
+
opts = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: \n\tnicolus --input listes.csv --output combinaison.csv\n\tnicolus -i listes.csv -o combinaison.csv --inverse\n"
|
12
|
+
|
13
|
+
opts.separator ""
|
14
|
+
opts.separator "Mandatory options:"
|
15
|
+
|
16
|
+
opts.on("-i", "--input [FILE]", :REQUIRED, String, "Csv File with lists of words") do |i|
|
17
|
+
options[:input] = i
|
18
|
+
end
|
19
|
+
opts.on("-o", "--output [FILE]", :REQUIRED, String, "Csv File to store the result") do |o|
|
20
|
+
options[:output] = o
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.separator ""
|
24
|
+
opts.separator "Optional options:"
|
25
|
+
|
26
|
+
opts.on("-I", "--inverse", "Generate inverse combinaison") do |inv|
|
27
|
+
options[:inverse] = inv
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.separator ""
|
31
|
+
opts.separator "Common options:"
|
32
|
+
|
33
|
+
# No argument, shows at tail. This will print an options summary.
|
34
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
35
|
+
puts opts
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if (args.size == 0)
|
41
|
+
# No args specify > running help
|
42
|
+
opts.parse!(["--help"])
|
43
|
+
else
|
44
|
+
opts.parse!(args)
|
45
|
+
end
|
46
|
+
|
47
|
+
options
|
48
|
+
end # parse()
|
49
|
+
end # class Optparse
|
50
|
+
end # module Nicolus
|
51
|
+
|
52
|
+
options = Nicolus::OptParse.parse(ARGV)
|
53
|
+
comb = Nicolus::Combinaison.new(options[:input], options[:output], options[:inverse])
|
54
|
+
comb.run
|
data/test/listes.csv
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/nicolus.rb'
|
3
|
+
|
4
|
+
class TestNicolus < Test::Unit::TestCase
|
5
|
+
def test_run_2_col
|
6
|
+
comb = Nicolus::Combinaison.new("test/listes.csv", "test/combinaison_2_col.csv")
|
7
|
+
comb.run
|
8
|
+
assert File.exist?("test/combinaison_2_col.csv")
|
9
|
+
File.delete "test/combinaison_2_col.csv"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_run_2_col_inverse
|
13
|
+
comb = Nicolus::Combinaison.new("test/listes.csv", "test/combinaison_2_col_inverse.csv", true)
|
14
|
+
comb.run
|
15
|
+
assert File.exist?("test/combinaison_2_col_inverse.csv")
|
16
|
+
File.delete "test/combinaison_2_col_inverse.csv"
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_run_3_col
|
20
|
+
comb = Nicolus::Combinaison.new("test/listes_3_col.csv", "test/combinaison_3_col.csv") #, true)
|
21
|
+
comb.run
|
22
|
+
assert File.exist?("test/combinaison_3_col.csv")
|
23
|
+
File.delete "test/combinaison_3_col.csv"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_run_3_col_inverse
|
27
|
+
comb = Nicolus::Combinaison.new("test/listes_3_col.csv", "test/combinaison_3_col_inverse.csv", true)
|
28
|
+
comb.run
|
29
|
+
assert File.exist?("test/combinaison_3_col_inverse.csv")
|
30
|
+
File.delete "test/combinaison_3_col_inverse.csv"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_unquote_normal
|
34
|
+
to_unquote = "abc"
|
35
|
+
to_unquote.unquote!
|
36
|
+
assert_equal "abc", to_unquote
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_unquote_1_quote
|
40
|
+
to_unquote = "\"abc"
|
41
|
+
to_unquote.unquote!
|
42
|
+
assert_equal "abc", to_unquote
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_unquote_2_quotes
|
46
|
+
to_unquote = "\"abc\""
|
47
|
+
to_unquote.unquote!
|
48
|
+
assert_equal "abc", to_unquote
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_unquote_3_quotes
|
52
|
+
to_unquote = "\"ab\"c\""
|
53
|
+
to_unquote.unquote!
|
54
|
+
assert_equal "ab\"c", to_unquote
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: nicolus
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2008-02-15 00:00:00 +01:00
|
8
|
+
summary: Nicolus is a simple program to make all possible combination out of 2 or more lists of words.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: pub.cog@gmail.com
|
12
|
+
homepage: http://nicolus.rubyforge.org/
|
13
|
+
rubyforge_project: nicolus
|
14
|
+
description: "Nicolus is a simple program to make all possible combination out of 2 or more lists of words. == FEATURES/PROBLEMS: * Command line parser * \"inverse\" generate \"aaa 111\" and \"111 aaa\" == SYNOPSIS:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Benjamin Francisoud
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/nicolus
|
37
|
+
- bin/nicolus.bat
|
38
|
+
- lib/nicolus.rb
|
39
|
+
- lib/opt_parse.rb
|
40
|
+
- test/listes.csv
|
41
|
+
- test/listes_3_col.csv
|
42
|
+
- test/test_nicolus.rb
|
43
|
+
test_files:
|
44
|
+
- test/test_nicolus.rb
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.txt
|
48
|
+
extra_rdoc_files:
|
49
|
+
- History.txt
|
50
|
+
- Manifest.txt
|
51
|
+
- README.txt
|
52
|
+
executables:
|
53
|
+
- nicolus
|
54
|
+
- nicolus.bat
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
dependencies:
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: hoe
|
62
|
+
version_requirement:
|
63
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.3.0
|
68
|
+
version:
|