breakverter 1.2.0 → 2.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.
@@ -1,53 +0,0 @@
1
- === 1.2.0 / 2009-04-05
2
-
3
- * 2 major enhancements
4
-
5
- * Namespaced into module Aef
6
- * Instance method added for on demand inclusion into the String class
7
-
8
- * 5 minor enhancements
9
-
10
- * Better metadata for gem
11
- * Test refactoring
12
- * Minor refactorings
13
- * Improved documentation
14
- * Added test for --version command
15
-
16
- * 1 minor bugfix
17
-
18
- * Fixed some bugs related to Ruby 1.8.6
19
-
20
- === 1.1.1 / 2009-03-08
21
-
22
- * minor enhancement
23
-
24
- * Added a --version command to output version and licensing information
25
- * Some test refactoring
26
- * Some more comments
27
-
28
- === 1.1.0 / 2009-03-01
29
-
30
- * 2 major enhancements
31
-
32
- * Added automated tests for the commandline tool
33
- * Tested compatibility with ruby 1.9.1
34
-
35
- * 1 minor enhancement
36
-
37
- * Added support for custom string linebreak encodings in library
38
-
39
- === 1.0.1 / 2009-02-24
40
-
41
- * 1 minor enhancement
42
-
43
- * Now tested on Windows XP
44
-
45
- * 1 minor bugfix
46
-
47
- * Bugfixes for commandline use
48
-
49
- === 1.0.0 / 2009-02-24
50
-
51
- * 1 major enhancement
52
-
53
- * Birthday!
@@ -1,12 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- README.rdoc
4
- COPYING.txt
5
- Rakefile
6
- bin/breakverter
7
- lib/breakverter.rb
8
- lib/breakverter/breakverter.rb
9
- spec/breakverter_spec.rb
10
- spec/fixtures/unix.txt
11
- spec/fixtures/windows.txt
12
- spec/fixtures/mac.txt
@@ -1,161 +0,0 @@
1
- = BreakVerter
2
-
3
- * Project: https://rubyforge.org/projects/aef/
4
- * RDoc: http://aef.rubyforge.org/breakverter/
5
- * Github: http://github.com/aef/breakverter/
6
-
7
- == DESCRIPTION:
8
-
9
- BreakVerter is a Ruby library and commandline tool for conversion of text
10
- between linebreak encoding formats of unix, windows or mac.
11
-
12
- == FEATURES/PROBLEMS:
13
-
14
- * Usable as library and commandline tool
15
- * Tested and fully working on:
16
- * Ubuntu Linux 8.10 i386_64 (Ruby 1.8.7 and 1.9.1p0)
17
- * Debian GNU/Linux 4.0 i386 (Ruby 1.8.6)
18
- * Windows XP i386 (Ruby 1.8.6)
19
- * The commandline tool doesn't work with Ruby 1.9.x because the user-choices gem
20
- is not yet updated. A patch is available here:
21
- https://rubyforge.org/tracker/index.php?func=detail&aid=24307&group_id=4192&atid=16176
22
-
23
- == SYNOPSIS:
24
-
25
- === Commandline
26
-
27
- The default output encoding is unix. You can also choose mac and windows.
28
-
29
- breakverter -o windows unix.txt windows.txt
30
-
31
- If no target file is specified the output will be sent to STDOUT.
32
-
33
- breakverter -o windows mac.txt > windows.txt
34
-
35
- You can set the default with the environment variable BREAKVERTER_OUTPUT.
36
-
37
- export BREAKVERTER_OUTPUT=mac
38
-
39
- breakverter windows.txt mac.txt
40
-
41
- === Library
42
-
43
- First of all you have to load the BreakVerter gem:
44
-
45
- require 'breakverter'
46
-
47
- You can put strings or objects responding to to_s into the convert method and
48
- optionally define a target linebreak encoding. The default encoding is :unix.
49
- You can also choose :mac and :windows. Notice that the :mac encoding is
50
- deprecated. Modern Apple machines also use :unix linebreak encoding.
51
-
52
- windows_string = "Abcdef\r\nAbcdef\r\nAbcdef"
53
-
54
- Aef::BreakVerter.convert(windows_string, :unix) #=> "Abcdef\nAbcdef\nAbcdef"
55
-
56
- Alternatively you could include BreakVerter into the String class and use it in
57
- the following way:
58
-
59
- class String
60
- include Aef::BreakVerter
61
- end
62
-
63
- "Abcdef\nAbcdef\nAbcdef".linebreaks(:mac) #=> "Abcdef\rAbcdef\rAbcdef"
64
-
65
- == REQUIREMENTS:
66
-
67
- * rubygems
68
-
69
- === Additional for commandline
70
- * user-choices
71
-
72
- === Additional for automated testing
73
- * hoe
74
- * rspec
75
- * sys-uname
76
-
77
- == INSTALL:
78
-
79
- === Normal
80
-
81
- gem install breakverter
82
-
83
- Additionally for the commandline tool:
84
-
85
- gem install user-choices
86
-
87
- === High security (recommended)
88
-
89
- There is a high security installation option available through rubygems. It is
90
- highly recommended over the normal installation, although it may be a bit less
91
- comfortable. To use the installation method, you will need my public key, which
92
- I use for cryptographic signatures on all my gems. You can find the public key
93
- and more detailed verification information in the aef-certificates section of my
94
- rubyforge project[https://rubyforge.org/frs/?group_id=7890&release_id=31749]
95
-
96
- Add the key to your rubygems' trusted certificates by the following command:
97
-
98
- gem cert --add aef.pem
99
-
100
- Now you can install the gem while automatically verifying it's signature by the
101
- following command:
102
-
103
- gem install breakverter -P HighSecurity
104
-
105
- Please notice that you will need other keys for dependent libraries, so you may
106
- have to install dependencies manually.
107
-
108
- === Automated testing
109
-
110
- You can test this package through rspec on your system. First find the path
111
- where the gem was installed to:
112
-
113
- gem which breakverter
114
-
115
- Go into the root directory of the installed gem and run the following command
116
- to start the test runner:
117
-
118
- rake spec
119
-
120
- On Windows systems you have to run the following instead:
121
-
122
- spec spec/**/*_spec.rb
123
-
124
- If something goes wrong you should be noticed through failing examples.
125
-
126
- == DEVELOPMENT:
127
-
128
- This software is developed in the source code management system git hosted
129
- at github.com. You can download the most recent sourcecode through the following
130
- command:
131
-
132
- git clone git://github.com/aef/breakverter.git
133
-
134
- Help on making this software better is always very appreciated. If you want your
135
- changes to be included in the official release, please send me a patch through
136
- the project's tracker[https://rubyforge.org/tracker/?group_id=7890] at
137
- rubyforge.org. You can generate a patch-file by the following command:
138
-
139
- git diff > patch.diff
140
-
141
- Please make sure to write tests for your changes and notice that I can't promise
142
- to include your changes before reviewing them.
143
-
144
- == LICENSE:
145
-
146
- Copyright 2009 Alexander E. Fischer <aef@raxys.net>
147
-
148
- This file is part of BreakVerter.
149
-
150
- BreakVerter is free software: you can redistribute it and/or modify
151
- it under the terms of the GNU General Public License as published by
152
- the Free Software Foundation, either version 3 of the License, or
153
- (at your option) any later version.
154
-
155
- This program is distributed in the hope that it will be useful,
156
- but WITHOUT ANY WARRANTY; without even the implied warranty of
157
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
158
- GNU General Public License for more details.
159
-
160
- You should have received a copy of the GNU General Public License
161
- along with this program. If not, see <http://www.gnu.org/licenses/>.
data/Rakefile DELETED
@@ -1,19 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'rubygems'
4
- require 'hoe'
5
- require './lib/breakverter.rb'
6
-
7
- Hoe.new('breakverter', Aef::BreakVerter::VERSION) do |p|
8
- p.rubyforge_name = 'aef'
9
- p.developer('Alexander E. Fischer', 'aef@raxys.net')
10
- p.extra_dev_deps = %w{user-choices rspec sys-uname}
11
- p.url = 'https://rubyforge.org/projects/aef/'
12
- p.readme_file = 'README.rdoc'
13
- p.extra_rdoc_files = %w{README.rdoc}
14
- p.spec_extras = {
15
- :rdoc_options => ['--main', 'README.rdoc', '--inline-source', '--line-numbers', '--title', 'BreakVerter']
16
- }
17
- end
18
-
19
- # vim: syntax=Ruby
@@ -1,128 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
4
- #
5
- # This file is part of BreakVerter.
6
- #
7
- # BreakVerter is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU General Public License as published by
9
- # the Free Software Foundation, either version 3 of the License, or
10
- # (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
-
20
- # TODO: If user-choices patch gets accepted, use :one_way => true for --version
21
- # TODO: If user-choices patch gets accepted, use :upcase for environment variables
22
-
23
- # If library is not locally accessible, use gem to include it.
24
- begin
25
- require 'lib/breakverter'
26
- rescue LoadError
27
- require 'rubygems'
28
- require 'breakverter'
29
- end
30
-
31
- # User friendly message if user-choices is not available
32
- begin
33
- require 'user-choices'
34
- rescue LoadError
35
- warn "This command needs the user-choices gem to be installed.\n\nSolution: gem install user-choices"; exit false
36
- end
37
-
38
- # Application class for commandline interface
39
- class Aef::BreakVerter::Application < UserChoices::Command
40
- include UserChoices
41
-
42
- # Prepare configuration sources
43
- def add_sources(builder)
44
- builder.add_source(
45
- CommandLineSource, :usage,
46
- "Usage: #$PROGRAM_NAME [options] input-file [output-file]\n\n",
47
- "Convert a file with any linebreak encoding to a specific linebreak encoding.\n",
48
- "Use the environment variable BREAKVERTER_OUTPUT to specify a default output encoding.\n"
49
- )
50
-
51
- builder.add_source(EnvironmentSource, :mapping,
52
- :output => 'BREAKVERTER_OUTPUT'
53
- )
54
- end
55
-
56
- # Define configuration options
57
- def add_choices(builder)
58
- output_values = Aef::BreakVerter::BREAKS.keys.map{|key| key.to_s}
59
- builder.add_choice(:output, :default => 'unix', :type => output_values) do |cli|
60
- cli.uses_option('-o', '--output PLATFORM',
61
- "Output formatting. Possible settings: #{Aef::BreakVerter::BREAKS.keys.join(', ')}")
62
- end
63
-
64
- builder.add_choice(:version, :default => false, :type => :boolean) do |cli|
65
- cli.uses_switch('-v', '--version', 'Display version and licensing information')
66
- end
67
-
68
- builder.add_choice(:filenames, :length => 0..2) {|cli| cli.uses_arglist}
69
- end
70
-
71
- # Manual option post processing
72
- def postprocess_user_choices
73
- version if @user_choices[:version]
74
-
75
- @user_choices[:input_filename] = @user_choices[:filenames][0]
76
- @user_choices[:output_filename] = @user_choices[:filenames][1] || '-'
77
- end
78
-
79
- # Version and licensing information output
80
- def version
81
- name = 'BreakVerter'
82
- puts "#{name} #{Aef::BreakVerter::VERSION}"
83
- puts
84
- puts 'Project: https://rubyforge.org/projects/aef/'
85
- puts "RDoc: http://aef.rubyforge.org/#{name.downcase}/"
86
- puts "Github: http://github.com/aef/#{name.downcase}/"
87
- puts
88
- puts 'Copyright 2009 Alexander E. Fischer <aef@raxys.net>'
89
- # Read and print licensing information from the top of this file
90
- if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('1.8.6')
91
- puts File.read(__FILE__).map{|line| line[2..-1]}[5..17]
92
- else
93
- puts File.read(__FILE__).lines.map{|line| line[2..-1]}[5..17]
94
- end
95
- exit
96
- end
97
-
98
- # Main program
99
- def execute
100
- unless @user_choices[:input_filename]
101
- warn 'No input file given'; exit false
102
- end
103
-
104
- unless File.exists?(@user_choices[:input_filename])
105
- warn "Input file not found (#{@user_choices[:input_filename]})"; exit false
106
- end
107
-
108
- unless File.readable?(@user_choices[:input_filename])
109
- warn "Input file access denied (#{@user_choices[:input_filename]})"; exit false
110
- end
111
-
112
- result = Aef::BreakVerter.convert(File.read(@user_choices[:input_filename]), @user_choices[:output].to_sym)
113
-
114
- if @user_choices[:output_filename] == '-'
115
- puts result
116
- else
117
- @user_choices[:output_filename]
118
-
119
- unless File.writable?(File.dirname(@user_choices[:output_filename]))
120
- warn "Output file access denied (#{@user_choices[:output_filename]})"; exit false
121
- end
122
-
123
- File.open(@user_choices[:output_filename], 'w') {|f| f.write(result)}
124
- end
125
- end
126
- end
127
-
128
- S4tUtils.with_pleasant_exceptions {Aef::BreakVerter::Application.new.execute}
@@ -1,45 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of BreakVerter.
4
- #
5
- # BreakVerter is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
-
18
- # BreakVerter is Ruby library and commandline tool for conversion of text
19
- # between linebreak encoding formats of unix, windows or mac.
20
- module Aef::BreakVerter
21
- VERSION = '1.2.0'
22
-
23
- BREAKS = {
24
- :unix => "\n",
25
- :windows => "\r\n",
26
- :mac => "\r"
27
- }
28
-
29
- # Convert a file with any linebreak encoding to a specific linebreak encoding.
30
- #
31
- # If given output_encoding is not a key of BREAKS, all linebreaks are replaced
32
- # with output_encoding's content itself.
33
- def self.convert(input, output_encoding = :unix)
34
- if input.respond_to?(:to_s) then input = input.to_s
35
- else raise 'Input has to be a string or must support to_s' end
36
-
37
- input.gsub(/\r(?:\n)?|\n/, BREAKS[output_encoding] || output_encoding)
38
- end
39
-
40
- # Shortcut for direct receiver conversion, for example if BreakVerter is
41
- # included into the string class
42
- def linebreaks(output_encoding = :unix)
43
- Aef::BreakVerter.convert(self, output_encoding)
44
- end
45
- end
@@ -1,175 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of BreakVerter.
4
- #
5
- # BreakVerter is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # This program is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
-
18
- require 'lib/breakverter'
19
- require 'tempfile'
20
-
21
- require 'rubygems'
22
- require 'sys/uname'
23
-
24
- module BreakVerterSpecHelper
25
- # If there is a way to get the executable path of the currently running ruby
26
- # interpreter, please tell me how.
27
- warn 'Attention: If the ruby interpreter to be tested with is not ruby in the' +
28
- "default path, you have to change this manually in #{__FILE__} line #{__LINE__ + 1}"
29
- RUBY_PATH = 'ruby'
30
-
31
- def executable_path
32
- "#{RUBY_PATH} bin/breakverter"
33
- end
34
-
35
- def fixture_path(name)
36
- File.join('spec/fixtures', name)
37
- end
38
-
39
- def windows?
40
- Sys::Uname.sysname.downcase.include?('windows')
41
- end
42
-
43
- def unix_fixture
44
- "Abcdef\nAbcdef\nAbcdef"
45
- end
46
-
47
- def windows_fixture
48
- "Abcdef\r\nAbcdef\r\nAbcdef"
49
- end
50
-
51
- def mac_fixture
52
- "Abcdef\rAbcdef\rAbcdef"
53
- end
54
-
55
- def custom_fixture
56
- "AbcdeffnordAbcdeffnordAbcdef"
57
- end
58
- end
59
-
60
- describe Aef::BreakVerter do
61
- include BreakVerterSpecHelper
62
-
63
- context 'library' do
64
- it 'should convert correctly from unix to windows format' do
65
- Aef::BreakVerter.convert(unix_fixture, :windows).should eql(windows_fixture)
66
- end
67
-
68
- it 'should convert correctly from unix to mac format' do
69
- Aef::BreakVerter.convert(unix_fixture, :mac).should eql(mac_fixture)
70
- end
71
-
72
- it 'should convert correctly from unix to a custom format' do
73
- Aef::BreakVerter.convert(unix_fixture, 'fnord').should eql(custom_fixture)
74
- end
75
-
76
- it 'should convert correctly from windows to unix format' do
77
- Aef::BreakVerter.convert(windows_fixture, :unix).should eql(unix_fixture)
78
- end
79
-
80
- it 'should convert correctly from windows to mac format' do
81
- Aef::BreakVerter.convert(windows_fixture, :mac).should eql(mac_fixture)
82
- end
83
-
84
- it 'should convert correctly from unix to a custom format' do
85
- Aef::BreakVerter.convert(windows_fixture, 'fnord').should eql(custom_fixture)
86
- end
87
-
88
- it 'should convert correctly from mac to unix format' do
89
- Aef::BreakVerter.convert(mac_fixture, :unix).should eql(unix_fixture)
90
- end
91
-
92
- it 'should convert correctly from mac to windows format' do
93
- Aef::BreakVerter.convert(mac_fixture, :windows).should eql(windows_fixture)
94
- end
95
-
96
- it 'should convert correctly from unix to a custom format' do
97
- Aef::BreakVerter.convert(mac_fixture, 'fnord').should eql(custom_fixture)
98
- end
99
- end
100
-
101
- context 'commandline tool' do
102
- it 'should use unix as default format' do
103
- `#{executable_path} #{fixture_path('windows.txt')}`.should eql(unix_fixture + "\n")
104
- end
105
-
106
- it 'should accept -o option to specify output format' do
107
- `#{executable_path} -o mac #{fixture_path('unix.txt')}`.should eql(mac_fixture + "\n")
108
- end
109
-
110
- it 'should also accept --output option to specify output format' do
111
- `#{executable_path} --output windows #{fixture_path('mac.txt')}`.should eql(windows_fixture + "\n")
112
- end
113
-
114
- it 'should abort on invalid output formats' do
115
- puts "\nAn error output after this line is expected behavior, simply ignore it:\n"
116
- `#{executable_path} -o fnord #{fixture_path('mac.txt')}`.should be_empty
117
- end
118
-
119
- it 'should accept BREAKVERTER_OUTPUT environment variable to specify output format' do
120
- if windows?
121
- `set BREAKVERTER_OUTPUT=mac`
122
- `#{executable_path} --output mac #{fixture_path('windows.txt')}`.should eql(mac_fixture + "\n")
123
- else
124
- `env BREAKVERTER_OUTPUT=mac #{executable_path} --output mac #{fixture_path('windows.txt')}`.should eql(mac_fixture + "\n")
125
- end
126
- end
127
-
128
- it 'should use output format specified with -o even if BREAKVERTER_OUTPUT environment variable is set' do
129
- if windows?
130
- `set BREAKVERTER_OUTPUT=windows`
131
- `#{executable_path} -o mac #{fixture_path('unix.txt')}`.should eql(mac_fixture + "\n")
132
- else
133
- `env BREAKVERTER_OUTPUT=windows #{executable_path} -o mac #{fixture_path('unix.txt')}`.should eql(mac_fixture + "\n")
134
- end
135
- end
136
-
137
- it 'should use a second argument as target file' do
138
- temp_file = Tempfile.open('breakverter_spec')
139
- location = temp_file.path
140
- temp_file.close
141
- temp_file.unlink
142
-
143
- `#{executable_path} --output windows #{fixture_path('unix.txt')} #{location}`.should be_empty
144
-
145
- File.read(location).should eql(windows_fixture)
146
- File.unlink(location)
147
- end
148
-
149
- it 'should display correct version and licensing information with the --version switch' do
150
- message = <<-EOF
151
- BreakVerter 1.2.0
152
-
153
- Project: https://rubyforge.org/projects/aef/
154
- RDoc: http://aef.rubyforge.org/breakverter/
155
- Github: http://github.com/aef/breakverter/
156
-
157
- Copyright 2009 Alexander E. Fischer <aef@raxys.net>
158
-
159
- BreakVerter is free software: you can redistribute it and/or modify
160
- it under the terms of the GNU General Public License as published by
161
- the Free Software Foundation, either version 3 of the License, or
162
- (at your option) any later version.
163
-
164
- This program is distributed in the hope that it will be useful,
165
- but WITHOUT ANY WARRANTY; without even the implied warranty of
166
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167
- GNU General Public License for more details.
168
-
169
- You should have received a copy of the GNU General Public License
170
- along with this program. If not, see <http://www.gnu.org/licenses/>.
171
- EOF
172
- `#{executable_path} --version`.should eql(message)
173
- end
174
- end
175
- end