linebreak 1.3.1 → 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,38 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of Linebreak.
4
- #
5
- # Linebreak is free software: you can redistribute it and/or modify it under the
6
- # terms of the GNU General Public License as published by the Free Software
7
- # Foundation, either version 3 of the License, or (at your option) any later
8
- # version.
9
- #
10
- # This program is distributed in the hope that it will be useful, but WITHOUT
11
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
- # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13
- # details.
14
- #
15
- # You should have received a copy of the GNU General Public License along with
16
- # this program. If not, see <http://www.gnu.org/licenses/>.
17
-
18
- require 'aef/linebreak/pathname_conversion'
19
-
20
- class Aef::Linebreak::VersionCommand
21
- def execute
22
- name = 'Linebreak'
23
- puts "#{name} #{Aef::Linebreak::VERSION}"
24
- puts
25
- puts 'Project: https://rubyforge.org/projects/linebreak/'
26
- puts "RDoc: http://#{name.downcase}.rubyforge.org/"
27
- puts "Github: http://github.com/aef/#{name.downcase}/"
28
- puts
29
- puts 'Copyright 2009 Alexander E. Fischer <aef@raxys.net>'
30
- # Read and print licensing information from the top of this file
31
- if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('1.8.6')
32
- puts File.read(__FILE__).map{|line| line[2..-1]}[3..15]
33
- else
34
- puts File.read(__FILE__).lines.map{|line| line[2..-1]}[3..15]
35
- end
36
- exit false
37
- end
38
- end
@@ -1,124 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of Linebreak.
4
- #
5
- # Linebreak 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 'pathname'
19
- require 'set'
20
-
21
- # Linebreak is Ruby library and commandline tool for conversion of text
22
- # between linebreak encoding formats of unix, windows or mac.
23
- #
24
- # If you want to use the String extension methods, simply use the following
25
- # command:
26
- #
27
- # require 'aef/linebreak/string_extension'
28
- module Aef::Linebreak
29
- autoload :ConversionToPathname, 'aef/linebreak/pathname_conversion'
30
- autoload :EncodeCommand, 'aef/linebreak/commands/encode'
31
- autoload :EncodingsCommand, 'aef/linebreak/commands/encodings'
32
- autoload :VersionCommand, 'aef/linebreak/commands/version'
33
-
34
- VERSION = '1.3.1'
35
-
36
- BREAK_BY_SYSTEM = {
37
- :unix => "\n",
38
- :windows => "\r\n",
39
- :mac => "\r"
40
- }
41
-
42
- SYSTEM_BY_BREAK = BREAK_BY_SYSTEM.invert
43
-
44
- BREAK_REGEXP = /(\r\n|[\r\n])/
45
-
46
- # Detects encoding systems of a string.
47
- #
48
- # Returns a Set with symbols of all encoding systems existent in the string.
49
- def self.encodings(input)
50
- if input.respond_to?(:to_s) then input = input.to_s
51
- else raise ArgumentError, 'Input needs to be a string or must support to_s' end
52
-
53
- occurences = Set.new
54
-
55
- input.scan(BREAK_REGEXP).each do |linebreak|
56
- occurences << SYSTEM_BY_BREAK[linebreak.first]
57
- end
58
-
59
- occurences
60
- end
61
-
62
- # Checks whether a string includes linebreaks of all the given encoding
63
- # systems.
64
- #
65
- # One or more systems can be given as an array or an argument list of symbols.
66
- #
67
- # Returns true or false.
68
- def self.encoding?(input, *encodings)
69
- systems = BREAK_BY_SYSTEM.keys
70
-
71
- encodings.flatten!
72
- encodings.each do |encoding|
73
- unless systems.include?(encoding)
74
- raise ArgumentError,
75
- %{Invalid encoding system. Available systems: #{systems.join(', ')}. Arguments are expected as symbols or an array of symbols.}
76
- end
77
- end
78
-
79
- Aef::Linebreak.encodings(input) == Set.new(encodings)
80
- end
81
-
82
- # Create a copy of a string with all the string's linebreaks replaced by
83
- # linebreaks of a specific system or a given replacement.
84
- #
85
- # If given output_encoding is not a key of BREAK_BY_SYSTEM, all linebreaks
86
- # are replaced with output_encoding's content itself.
87
- def self.encode(input, system_or_replacement = :unix)
88
- if input.respond_to?(:to_s) then input = input.to_s
89
- else raise ArgumentError, 'Input needs to be a string or must support to_s' end
90
-
91
- input.gsub(BREAK_REGEXP,
92
- BREAK_BY_SYSTEM[system_or_replacement] || system_or_replacement)
93
- end
94
-
95
- # Detects encoding systems of the string.
96
- #
97
- # Returns a Set with symbols of all encoding systems existent in the string.
98
- #
99
- # This method is supposed to be used as a method of String.
100
- def linebreak_encodings
101
- Aef::Linebreak.encodings(self)
102
- end
103
-
104
- # Checks whether the string includes linebreaks of all the given encoding
105
- # systems.
106
- #
107
- # One or more systems can be given as an array or an argument list of symbols.
108
- #
109
- # This method is supposed to be used as a method of String.
110
- def linebreak_encoding?(*encodings)
111
- Aef::Linebreak.encoding?(self, encodings)
112
- end
113
-
114
- # Create a copy of the string with all the string's linebreaks replaced by
115
- # linebreaks of a specific system or a given replacement.
116
- #
117
- # If given output_encoding is not a key of BREAK_BY_SYSTEM, all linebreaks
118
- # are replaced with output_encoding's content itself.
119
- #
120
- # This method is supposed to be used as a method of String.
121
- def linebreak_encode(system_or_replacement = :unix)
122
- Aef::Linebreak.encode(self, system_or_replacement)
123
- end
124
- end
@@ -1,44 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of Linebreak.
4
- #
5
- # Linebreak 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
- # This class adds the type :pathname to user-choices
19
- class Aef::Linebreak::ConversionToPathname < UserChoices::Conversion
20
- def self.described_by?(conversion_tag)
21
- conversion_tag == :pathname
22
- end
23
-
24
- def description
25
- "a pathname"
26
- end
27
-
28
- def suitable?(actual)
29
- true
30
- end
31
-
32
- def convert(value)
33
- case value
34
- when Array
35
- pathnames = []
36
-
37
- value.each {|path| pathnames << Pathname(path) }
38
-
39
- pathnames
40
- else
41
- Pathname(value)
42
- end
43
- end
44
- end
@@ -1,22 +0,0 @@
1
- # Copyright 2009 Alexander E. Fischer <aef@raxys.net>
2
- #
3
- # This file is part of Linebreak.
4
- #
5
- # Linebreak 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 'aef/linebreak'
19
-
20
- class String
21
- include Aef::Linebreak
22
- end
@@ -1 +0,0 @@
1
- Abcdef
@@ -1,2 +0,0 @@
1
- Abcdef
2
- Abcdef
@@ -1,3 +0,0 @@
1
- Abcdef
2
- Abcdef
3
- Abcdef
@@ -1,3 +0,0 @@
1
- Abcdef
2
- Abcdef
3
- Abcdef
@@ -1,3 +0,0 @@
1
- Abcdef
2
- Abcdef
3
- Abcdef
@@ -1,3 +0,0 @@
1
- Abcdef
2
- Abcdef
3
- Abcdef
@@ -1,2 +0,0 @@
1
- Abcdef
2
- Abcdef
data/spec/spec.opts DELETED
@@ -1,4 +0,0 @@
1
- --colour
2
- --format progress
3
- --loadby mtime
4
- --reverse