colszowka-cucumber_table_formatter 0.1.0 → 0.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.rdoc CHANGED
@@ -1,6 +1,43 @@
1
- = cucumber_table_formatter
1
+ = cucumber_table_formatter - A formatter for Cucumber tables...
2
2
 
3
- Description goes here.
3
+ === Simple command line utility for formatting Cucumber tables properly, either from file or piped input
4
+
5
+ == Install with:
6
+ $ sudo gem install colszowka-cucumber_table_formatter --source http://gems.github.com
7
+
8
+ == Example from file
9
+ Assuming you have a file called 'some_file_containing_the_table.txt' that looks something like this:
10
+
11
+ | user | email | url |
12
+ | colszowka | colszowka@example.com | http://blog.olszowka.de |
13
+ | ruby-toolbox | rubytoolbox@example.com | http://ruby-toolbox.com |
14
+
15
+ $ format_cucumber_table some_file_containing_the_table.txt
16
+
17
+ Will print:
18
+
19
+ | user | email | url |
20
+ | colszowka | colszowka@example.com | http://blog.olszowka.de |
21
+ | ruby-toolbox | rubytoolbox@example.com | http://ruby-toolbox.com |
22
+
23
+ == Example from pipe
24
+
25
+ $ echo "| a | b |
26
+ | cd | ef |" | format_cucumber_table
27
+
28
+ Will print:
29
+
30
+ | a | b |
31
+ | cd | ef |
32
+
33
+ Piping is particularily useful when set up in your favorite editor as an external command (i.e. in gedit)
34
+ and you use the selected text as input and let the script output replace it - instant table formatting
35
+ inside your feature files!
36
+
37
+ TODO: More description goes here....
38
+
39
+ Note: No tests or documentation yet.. Don't be too picky about the implementation, too - it's just
40
+ hacked together so does what it's supposed to...
4
41
 
5
42
  == Note on Patches/Pull Requests
6
43
 
data/Rakefile CHANGED
@@ -5,8 +5,8 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "cucumber_table_formatter"
8
- gem.summary = %Q{TODO: one-line summary of your gem}
9
- gem.description = %Q{TODO: longer description of your gem}
8
+ gem.summary = %Q{Formatter for Cucumber tables}
9
+ gem.description = %Q{Simple command line utility for formatting Cucumber tables properly, either from file or piped input}
10
10
  gem.email = "christoph@olszowka.de"
11
11
  gem.homepage = "http://github.com/colszowka/cucumber_table_formatter"
12
12
  gem.authors = ["Christoph Olszowka"]
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 0
4
+ :minor: 2
@@ -1 +1,13 @@
1
- puts "test..."
1
+ #!/usr/bin/ruby
2
+
3
+ # Load table formatter class
4
+ require File.join(File.dirname(__FILE__), '../lib/cucumber_table_formatter')
5
+
6
+ # Check for input
7
+ unless input = readlines or (ARGV[0] and input = File.read(ARGV[0]).split("\n"))
8
+ puts "Please specify filename!"
9
+ exit 1
10
+ end
11
+
12
+ # Process input and print it
13
+ print CucumberTableFormatter.new(input).formatted
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cucumber_table_formatter}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Christoph Olszowka"]
12
+ s.date = %q{2009-09-18}
13
+ s.default_executable = %q{format_cucumber_table}
14
+ s.description = %q{Simple command line utility for formatting Cucumber tables properly, either from file or piped input}
15
+ s.email = %q{christoph@olszowka.de}
16
+ s.executables = ["format_cucumber_table"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION.yml",
28
+ "bin/format_cucumber_table",
29
+ "cucumber_table_formatter.gemspec",
30
+ "lib/cucumber_table_formatter.rb",
31
+ "test/cucumber_table_formatter_test.rb",
32
+ "test/test_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/colszowka/cucumber_table_formatter}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Formatter for Cucumber tables}
39
+ s.test_files = [
40
+ "test/cucumber_table_formatter_test.rb",
41
+ "test/test_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ $KCODE = 'u'
2
+ require 'jcode'
3
+
4
+ class CucumberTableFormatter
5
+ attr_accessor :lines
6
+ attr_reader :whitespace
7
+ attr_reader :columns
8
+
9
+ class Column
10
+ attr_accessor :values
11
+
12
+ def initialize
13
+ @values = []
14
+ end
15
+
16
+ def formatted_values
17
+ @formatted_values ||= values.map do |value|
18
+ value_length = value.jlength # Required for ruby 1.8 utf-8 issues
19
+ " " + " " * (longest_value - value_length) + value + " "
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def longest_value
26
+ @longest_value ||= values.sort_by {|v| v.length }.reverse.first.length
27
+ end
28
+ end
29
+
30
+ def initialize(table_string)
31
+ self.lines = table_string.reject { |l| l.strip.chomp.length == 0 }.map(&:chomp)
32
+ @whitespace = self.lines.first.split("|")[0].length
33
+ read_columns!
34
+ end
35
+
36
+ def formatted
37
+ (0...lines.length).to_a.map { |i| " "*whitespace + "|" + formatted_line(i) + "|" }.join("\n")
38
+ end
39
+
40
+ def formatted_line(index)
41
+ columns.map do |c|
42
+ c.formatted_values[index]
43
+ end.join("|")
44
+ end
45
+
46
+ private
47
+
48
+ #
49
+ # Process the lines
50
+ #
51
+ def read_columns!
52
+ @columns ||= []
53
+ lines.each do |line|
54
+ line.strip.chomp.split("|").reject {|l| l.length == 0}.each_with_index do |value, column_index|
55
+ # Initialize column when needed
56
+ @columns[column_index] ||= Column.new
57
+ @columns[column_index].values << value.strip.chomp
58
+ end
59
+ end
60
+ end
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colszowka-cucumber_table_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christoph Olszowka
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- description: "TODO: longer description of your gem"
25
+ description: Simple command line utility for formatting Cucumber tables properly, either from file or piped input
26
26
  email: christoph@olszowka.de
27
27
  executables:
28
28
  - format_cucumber_table
@@ -37,6 +37,9 @@ files:
37
37
  - LICENSE
38
38
  - README.rdoc
39
39
  - Rakefile
40
+ - VERSION.yml
41
+ - bin/format_cucumber_table
42
+ - cucumber_table_formatter.gemspec
40
43
  - lib/cucumber_table_formatter.rb
41
44
  - test/cucumber_table_formatter_test.rb
42
45
  - test/test_helper.rb
@@ -66,7 +69,7 @@ rubyforge_project:
66
69
  rubygems_version: 1.3.5
67
70
  signing_key:
68
71
  specification_version: 3
69
- summary: "TODO: one-line summary of your gem"
72
+ summary: Formatter for Cucumber tables
70
73
  test_files:
71
74
  - test/cucumber_table_formatter_test.rb
72
75
  - test/test_helper.rb