Class: ImproveTypography::Processors::Nbsp
- Inherits:
-
ImproveTypography::Processor
- Object
- Struct
- ImproveTypography::Processor
- ImproveTypography::Processors::Nbsp
- Defined in:
- lib/improve_typography/processors/nbsp.rb
Instance Attribute Summary
Attributes inherited from ImproveTypography::Processor
Instance Method Summary collapse
Methods inherited from ImproveTypography::Processor
Constructor Details
This class inherits a constructor from ImproveTypography::Processor
Instance Method Details
#call ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/improve_typography/processors/nbsp.rb', line 4 def call return str unless str.match?(/(\A|\s+)(\S|\d+)([\.?!]?)(\s+|\z)/) str .gsub(/(\s+)(\S|\d+|\S\.)(\s+)(\S)/, '\1\2 \4') # in the middle of string .gsub(/\A(\w|\d+|\w\.)(\s+)(\S)/, '\1 \3') # at the beginning of string .gsub(/([^\S\n])(\S|\d+|\S\.)(\z|[\.?!]\z|[\.?!]\s)/, ' \2\3') # at the end of string!! .gsub(/(\A|\s+)(©)(\s+)(\d+)/, '\1\2 \4') .gsub(/(\A|\s+)(No\.|Vol\.)(\s+)(\d+)/, '\1\2 \3') end |