Class: String

Inherits:
Object show all
Defined in:
lib/qipowl/core/monkeypatches.rb

Overview

Bowling string means producing interpreter-safe text basing on ascii input.

Constant Summary collapse

NBSP =
"\u{00A0}"
SYMBOL_FOR_SPACE =

"\u{2420}"
WIDESPACE =
"\u{FF00}"
EN_SPACE =
"\u{2002}"
EM_SPACE =
"\u{2003}"
THREE_PER_EM_SPACE =
"\u{2004}"
FOUR_PER_EM_SPACE =
"\u{2005}"
SIX_PER_EM_SPACE =
"\u{2006}"
FIGURE_SPACE =
"\u{2007}"
PUNCTUATION_SPACE =
"\u{2008}"
THIN_SPACE =
"\u{2009}"
HAIR_SPACE =
"\u{200A}"
ZERO_WIDTH_SPACE =
"\u{200B}"
NARROW_NO_BREAK_SPACE =
"\u{202F}"
MEDIUM_MATHEMATICAL_SPACE =
"\u{205F}"
ZERO_WIDTH_NO_BREAK_SPACE =
"\u{FEFF}"
IDEOGRAPHIC_SPACE =
"\u{3000}"
CARRIAGE_RETURN =
'␍'
NULL =
'␀'
ASCII_ALL =
[ASCII_SYMBOLS, ASCII_DIGITS, ASCII_LETTERS_SMALL, ASCII_LETTERS_CAP]
CODEPOINT_ORIGIN =

For FULLWIDTH characters

0xFF00 - 0x0020
UTF_ALL =
[UTF_SYMBOLS.values, UTF_DIGITS.values, UTF_LETTERS_SMALL.values, UTF_LETTERS_CAP.values]
UTF_ASCII =
UTF_SYMBOLS.merge(UTF_DIGITS).merge(UTF_LETTERS_SMALL).merge(UTF_LETTERS_CAP)
ASCII_UTF =
UTF_ASCII.invert
HTML_ENTITIES =

Instance Method Summary collapse

Instance Method Details

#bowlObject



78
79
80
81
# File 'lib/qipowl/core/monkeypatches.rb', line 78

def bowl
  (out = self.dup).bowl!
  out
end

#bowl!Object



75
76
77
# File 'lib/qipowl/core/monkeypatches.rb', line 75

def bowl!
  self.gsub!(/[#{Regexp.quote(ASCII_ALL.join)}]/, UTF_ASCII)
end

#carriageObject



110
111
112
# File 'lib/qipowl/core/monkeypatches.rb', line 110

def carriage
  self.gsub(/\R/, " #{CARRIAGE_RETURN} ")
end

#carriage!Object



113
114
115
# File 'lib/qipowl/core/monkeypatches.rb', line 113

def carriage!
  self.gsub!(/\R/, " #{CARRIAGE_RETURN} ")
end

#hsub(hash) ⇒ Object



71
72
73
74
# File 'lib/qipowl/core/monkeypatches.rb', line 71

def hsub hash
  (out = self.dup).hsub! hash
  out
end

#hsub!(hash) ⇒ Object



68
69
70
# File 'lib/qipowl/core/monkeypatches.rb', line 68

def hsub! hash
  self.gsub!(/#{hash.keys.join('|')}/, hash)
end

#spacefyObject



92
93
94
95
# File 'lib/qipowl/core/monkeypatches.rb', line 92

def spacefy
  (out = self.dup).spacefy!
  out
end

#spacefy!Object



89
90
91
# File 'lib/qipowl/core/monkeypatches.rb', line 89

def spacefy!
  self.gsub!(' ', SYMBOL_FOR_SPACE)
end

#to_filenameObject



133
134
135
# File 'lib/qipowl/core/monkeypatches.rb', line 133

def to_filename
  self.gsub(/[#{Regexp.quote(ASCII_SYMBOLS.join)}]/, UTF_ASCII).gsub(/\s/, "#{NBSP}")[0..50]
end

#unbowlObject



85
86
87
88
# File 'lib/qipowl/core/monkeypatches.rb', line 85

def unbowl
  (out = self.dup).unbowl!
  out
end

#unbowl!Object



82
83
84
# File 'lib/qipowl/core/monkeypatches.rb', line 82

def unbowl!
  self.gsub!(/[#{Regexp.quote(UTF_ALL.join)}]/, ASCII_UTF)
end

#uncarriageObject



116
117
118
119
# File 'lib/qipowl/core/monkeypatches.rb', line 116

def uncarriage
  self.gsub(/ #{CARRIAGE_RETURN} /, %Q(
))
end

#uncarriage!Object



120
121
122
123
# File 'lib/qipowl/core/monkeypatches.rb', line 120

def uncarriage!
  self.gsub!(/ #{CARRIAGE_RETURN} /, %Q(
))
end

#unspacefyObject



99
100
101
102
# File 'lib/qipowl/core/monkeypatches.rb', line 99

def unspacefy
  (out = self.dup).unspacefy!
  out
end

#unspacefy!Object



96
97
98
# File 'lib/qipowl/core/monkeypatches.rb', line 96

def unspacefy!
  self.gsub!(/#{SYMBOL_FOR_SPACE}/, ' ')
end

#unuglifyObject



104
105
106
# File 'lib/qipowl/core/monkeypatches.rb', line 104

def unuglify
  self.unbowl.unspacefy.uncarriage.strip
end

#un␚ifyObject



125
126
127
# File 'lib/qipowl/core/monkeypatches.rb', line 125

def un

#vacant?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/qipowl/core/monkeypatches.rb', line 64

def vacant?
  nil? || empty?
end

#wstripObject



129
130
131
# File 'lib/qipowl/core/monkeypatches.rb', line 129

def wstrip
  self.gsub(/#{NBSP}/, '')
end