Module: Aef::Linebreak
- Defined in:
- lib/aef/linebreak.rb,
lib/aef/linebreak/version.rb
Overview
Namespace for the linebreak library
Constant Summary
- VERSION =
The currently loaded library version
Using Semantic Versioning (2.0.0-rc.1) rules
'2.0.1'.freeze
Class Method Summary (collapse)
-
+ (Object) encode(input, system_or_replacement = :unix)
Create a copy of a string with all the string's linebreaks replaced by linebreaks of a specific system or a given replacement.
-
+ (true, false) encoding?(input, *encodings)
Checks whether a string includes linebreaks of all the given encoding systems.
-
+ (Set<Symbol>) encodings(input)
Detects encoding systems of a string.
Instance Method Summary (collapse)
-
- (Object) linebreak_encode(system_or_replacement = :unix)
Create a copy of a string with all the string's linebreaks replaced by linebreaks of a specific system or a given replacement.
-
- (true, false) linebreak_encoding?(*encodings)
Checks whether a string includes linebreaks of all the given encoding systems.
-
- (Set<Symbol>) linebreak_encodings
Detects encoding systems of a string.
Class Method Details
+ (Object) encode(input, system) + (Object) encode(input, replacement)
Create a copy of a string with all the string's linebreaks replaced by linebreaks of a specific system or a given replacement.
105 106 107 108 109 110 111 |
# File 'lib/aef/linebreak.rb', line 105 def self.encode(input, system_or_replacement = :unix) if input.respond_to?(:to_s) then input = input.to_s else raise ArgumentError, 'Input needs to be a string or must support to_s' end input.gsub(BREAK_REGEXP, BREAK_BY_SYSTEM[system_or_replacement] || system_or_replacement) end |
+ (true, false) encoding?(input, *encodings)
Checks whether a string includes linebreaks of all the given encoding systems.
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/aef/linebreak.rb', line 80 def self.encoding?(input, *encodings) systems = BREAK_BY_SYSTEM.keys encodings.flatten! encodings.each do |encoding| unless systems.include?(encoding) raise ArgumentError, %{Invalid encoding system. Available systems: #{systems.join(', ')}. Arguments are expected as symbols or an array of symbols.} end end Aef::Linebreak.encodings(input) == Set.new(encodings) end |
+ (Set<Symbol>) encodings(input)
Detects encoding systems of a string.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aef/linebreak.rb', line 60 def self.encodings(input) if input.respond_to?(:to_s) then input = input.to_s else raise ArgumentError, 'Input needs to be a string or must support to_s' end occurences = Set.new input.scan(BREAK_REGEXP).each do |linebreak| occurences << SYSTEM_BY_BREAK[linebreak.first] end occurences end |
Instance Method Details
- (Object) encode(system) - (Object) encode(replacement)
Create a copy of a string with all the string's linebreaks replaced by linebreaks of a specific system or a given replacement.
This method is supposed to be used as a method of String.
145 146 147 |
# File 'lib/aef/linebreak.rb', line 145 def linebreak_encode(system_or_replacement = :unix) Aef::Linebreak.encode(self, system_or_replacement) end |
- (true, false) linebreak_encoding?(*encodings)
Checks whether a string includes linebreaks of all the given encoding systems.
This method is supposed to be used as a method of String.
130 131 132 |
# File 'lib/aef/linebreak.rb', line 130 def linebreak_encoding?(*encodings) Aef::Linebreak.encoding?(self, encodings) end |
- (Set<Symbol>) linebreak_encodings
Detects encoding systems of a string.
This method is supposed to be used as a method of String.
118 119 120 |
# File 'lib/aef/linebreak.rb', line 118 def linebreak_encodings Aef::Linebreak.encodings(self) end |