nicolus 1.1.0 → 1.2.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/README.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  = nicolus
2
- http://nicolus.rubyforge.org/
2
+ http://benjamin.francisoud.googlepages.com/nicolus
3
3
  by Benjamin Francisoud
4
4
 
5
5
  == DESCRIPTION:
@@ -14,16 +14,26 @@ Nicolus is a simple program to make all possible combination out of 2 or more li
14
14
  == SYNOPSIS:
15
15
 
16
16
  For example:
17
- listA = aaa, bbb, ccc
18
- listB = 111, 222
17
+ listA = [aaa, bbb, ccc]
18
+ listB = [111, 222]
19
19
 
20
20
  Combination will be:
21
- result= aaa 111, aaa 222, bbb 111, bbb 222, ccc 111, ccc 222
21
+ result= [aaa 111, aaa 222, bbb 111, bbb 222, ccc 111, ccc 222]
22
22
 
23
23
  == INSTALL:
24
24
 
25
25
  * gem install nicolus
26
26
 
27
+ == USAGE
28
+
29
+ * C:\>nicolus
30
+
31
+ == LINKS
32
+
33
+ * Homepage http://benjamin.francisoud.googlepages.com/nicolus
34
+ * RDoc http://nicolus.rubyforge.org/
35
+ * Rubyforge Page http://www.rubyforge.org/projects/nicolus
36
+
27
37
  == LICENSE:
28
38
 
29
39
  (The MIT License)
data/lib/nicolus.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'matrix'
2
+ require 'iconv'
2
3
 
3
4
  class Object
4
5
  def blank?
@@ -7,6 +8,16 @@ class Object
7
8
  end
8
9
 
9
10
  class String
11
+
12
+ def utf16_to_iso
13
+ converter = Iconv.new('ISO-8859-1//IGNORE//TRANSLIT', 'UTF-16')
14
+ converter.iconv(self)
15
+ end
16
+
17
+ def nicolus_split
18
+ self.chomp.gsub("\t", ',').split(',')
19
+ end
20
+
10
21
  def unquote!
11
22
  # remove first
12
23
  unless (gsub!(/\A\"/, '').nil?)
@@ -17,12 +28,16 @@ class String
17
28
  end
18
29
 
19
30
  module Nicolus
20
- VERSION = '1.1.0'
31
+ VERSION = '1.2.0'
21
32
 
33
+ # Usage
34
+ # comb = Nicolus::Combinaison.new("input.csv", "output.csv", true, true)
35
+ # comb.run
22
36
  class Combinaison
23
- def initialize(input_file, filename, inv=false)
37
+ def initialize(input_file, filename, inv=false, unicode=false)
24
38
  @input_file, @filename = input_file, filename
25
39
  @inv = inv
40
+ @unicode = unicode
26
41
  end
27
42
 
28
43
  def inverse?
@@ -35,9 +50,17 @@ module Nicolus
35
50
  # => [[a, b, c], [1, 2, 3], [A, B, C]]
36
51
  def create_lists
37
52
  list = []
38
- IO.foreach(@input_file) do |line|
39
- columns = line.chomp.split(',')
40
- list << columns
53
+ if (@unicode)
54
+ content = IO.read(@input_file).utf16_to_iso
55
+ content.split("\n").each do |line|
56
+ columns = line.nicolus_split # chomp.gsub("\t", ',').split(',')
57
+ list << columns
58
+ end
59
+ else
60
+ IO.foreach(@input_file) do |line|
61
+ columns = line.nicolus_split # chomp.gsub("\t", ',').split(',')
62
+ list << columns
63
+ end
41
64
  end
42
65
  # [[a, 1, A], [b, 2, B], [c, 3, C]] => [[a, b, c], [1, 2, 3], [A, B, C]]
43
66
  @listes = (Matrix.rows list).transpose.to_a
data/lib/opt_parse.rb CHANGED
@@ -3,6 +3,12 @@ require File.dirname(__FILE__) + '/nicolus.rb'
3
3
 
4
4
  module Nicolus
5
5
 
6
+ # Usage:
7
+ # options = Nicolus::OptParse.parse(ARGV)
8
+ # puts options[:input]
9
+ # puts options[:output]
10
+ # puts options[:inverse]
11
+ # puts options[:unicode]
6
12
  class OptParse
7
13
  # Return a structure describing the options.
8
14
  def self.parse(args)
@@ -27,6 +33,10 @@ module Nicolus
27
33
  options[:inverse] = inv
28
34
  end
29
35
 
36
+ opts.on("-U", "--unicode", "Input is Unicode") do |unicode|
37
+ options[:unicode] = unicode
38
+ end
39
+
30
40
  opts.separator ""
31
41
  opts.separator "Common options:"
32
42
 
@@ -50,5 +60,5 @@ module Nicolus
50
60
  end # module Nicolus
51
61
 
52
62
  options = Nicolus::OptParse.parse(ARGV)
53
- comb = Nicolus::Combinaison.new(options[:input], options[:output], options[:inverse])
63
+ comb = Nicolus::Combinaison.new(options[:input], options[:output], options[:inverse], options[:unicode])
54
64
  comb.run
data/test/test_nicolus.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'test/unit'
2
+ require 'fileutils.rb'
2
3
  require File.dirname(__FILE__) + '/../lib/nicolus.rb'
3
4
 
4
5
  class TestNicolus < Test::Unit::TestCase
@@ -29,7 +30,19 @@ class TestNicolus < Test::Unit::TestCase
29
30
  assert File.exist?("test/combinaison_3_col_inverse.csv")
30
31
  File.delete "test/combinaison_3_col_inverse.csv"
31
32
  end
33
+
34
+ def test_run_tabs_utf
35
+ comb = Nicolus::Combinaison.new("test/listes_tabs_utf.csv", "test/combinaison_tabs_utf.csv", false, true)
36
+ comb.run
37
+ assert File.exist?("test/combinaison_tabs_utf.csv")
38
+ end
32
39
 
40
+ def test_run_tabs_no_utf
41
+ comb = Nicolus::Combinaison.new("test/listes_tabs.csv", "test/combinaison_tabs.csv") #, true)
42
+ comb.run
43
+ assert File.exist?("test/combinaison_tabs.csv")
44
+ end
45
+
33
46
  def test_unquote_normal
34
47
  to_unquote = "abc"
35
48
  to_unquote.unquote!
@@ -53,4 +66,11 @@ class TestNicolus < Test::Unit::TestCase
53
66
  to_unquote.unquote!
54
67
  assert_equal "ab\"c", to_unquote
55
68
  end
69
+ <<<<<<< .mine
56
70
  end
71
+ =======
72
+
73
+ def teardown
74
+ FileUtils.rm_f Dir['test/combinaison*']
75
+ end
76
+ end>>>>>>> .r12
metadata CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: nicolus
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.0
7
- date: 2008-02-15 00:00:00 +01:00
6
+ version: 1.2.0
7
+ date: 2008-02-19 00:00:00 +01:00
8
8
  summary: Nicolus is a simple program to make all possible combination out of 2 or more lists of words.
9
9
  require_paths:
10
10
  - lib
11
11
  email: pub.cog@gmail.com
12
- homepage: http://nicolus.rubyforge.org/
12
+ homepage: http://benjamin.francisoud.googlepages.com/nicolus
13
13
  rubyforge_project: nicolus
14
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
15
  autorequire: