Class: String
- Defined in:
- lib/qipowl/core/monkeypatches.rb,
lib/qipowl/utils/unicode_strings.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
- #bowl ⇒ Object
- #bowl! ⇒ Object
- #capitalize ⇒ Object
- #capitalize! ⇒ Object
- #carriage(spaces = true) ⇒ Object
- #downcase ⇒ Object
- #downcase! ⇒ Object
- #hsub(hash) ⇒ Object
- #hsub!(hash) ⇒ Object
- #spacefy ⇒ Object
- #spacefy! ⇒ Object
- #to_filename ⇒ Object
- #unbowl ⇒ Object
- #unbowl! ⇒ Object
- #uncarriage(spaces = true) ⇒ Object
- #unspacefy ⇒ Object
- #unspacefy! ⇒ Object
- #unuglify ⇒ Object
- #un␚ify ⇒ Object
- #upcase ⇒ Object
- #upcase! ⇒ Object
- #vacant? ⇒ Boolean
- #wstrip ⇒ Object
Instance Method Details
#bowl ⇒ Object
79 80 81 82 |
# File 'lib/qipowl/core/monkeypatches.rb', line 79 def bowl (out = self.dup).bowl! out end |
#bowl! ⇒ Object
76 77 78 |
# File 'lib/qipowl/core/monkeypatches.rb', line 76 def bowl! self.gsub!(/[#{Regexp.quote(ASCII_ALL.join)}]/, UTF_ASCII) end |
#capitalize ⇒ Object
18 19 20 |
# File 'lib/qipowl/utils/unicode_strings.rb', line 18 def capitalize Unicode::capitalize(self) end |
#capitalize! ⇒ Object
21 22 23 |
# File 'lib/qipowl/utils/unicode_strings.rb', line 21 def capitalize! self.replace capitalize end |
#carriage(spaces = true) ⇒ Object
111 112 113 |
# File 'lib/qipowl/core/monkeypatches.rb', line 111 def carriage spaces = true self.gsub(/\R/, spaces ? " #{CARRIAGE_RETURN} " : "#{CARRIAGE_RETURN}") end |
#downcase ⇒ Object
6 7 8 |
# File 'lib/qipowl/utils/unicode_strings.rb', line 6 def downcase Unicode::downcase(self) end |
#downcase! ⇒ Object
9 10 11 |
# File 'lib/qipowl/utils/unicode_strings.rb', line 9 def downcase! self.replace downcase end |
#hsub(hash) ⇒ Object
72 73 74 75 |
# File 'lib/qipowl/core/monkeypatches.rb', line 72 def hsub hash (out = self.dup).hsub! hash out end |
#hsub!(hash) ⇒ Object
69 70 71 |
# File 'lib/qipowl/core/monkeypatches.rb', line 69 def hsub! hash self.gsub!(/#{hash.keys.join('|')}/, hash) end |
#spacefy ⇒ Object
93 94 95 96 |
# File 'lib/qipowl/core/monkeypatches.rb', line 93 def spacefy (out = self.dup).spacefy! out end |
#spacefy! ⇒ Object
90 91 92 |
# File 'lib/qipowl/core/monkeypatches.rb', line 90 def spacefy! self.gsub!(' ', SYMBOL_FOR_SPACE) end |
#to_filename ⇒ Object
127 128 129 |
# File 'lib/qipowl/core/monkeypatches.rb', line 127 def to_filename self.gsub(/[#{Regexp.quote(ASCII_SYMBOLS.join)}]/, UTF_ASCII).gsub(/\s/, "#{NBSP}")[0..50] end |
#unbowl ⇒ Object
86 87 88 89 |
# File 'lib/qipowl/core/monkeypatches.rb', line 86 def unbowl (out = self.dup).unbowl! out end |
#unbowl! ⇒ Object
83 84 85 |
# File 'lib/qipowl/core/monkeypatches.rb', line 83 def unbowl! self.gsub!(/[#{Regexp.quote(UTF_ALL.join)}]/, ASCII_UTF) end |
#uncarriage(spaces = true) ⇒ Object
114 115 116 117 |
# File 'lib/qipowl/core/monkeypatches.rb', line 114 def uncarriage spaces = true self.gsub(spaces ? /\s?#{CARRIAGE_RETURN}\s?/ : /#{CARRIAGE_RETURN}/, %Q( )) end |
#unspacefy ⇒ Object
100 101 102 103 |
# File 'lib/qipowl/core/monkeypatches.rb', line 100 def unspacefy (out = self.dup).unspacefy! out end |
#unspacefy! ⇒ Object
97 98 99 |
# File 'lib/qipowl/core/monkeypatches.rb', line 97 def unspacefy! self.gsub!(/#{SYMBOL_FOR_SPACE}/, ' ') end |
#unuglify ⇒ Object
105 106 107 |
# File 'lib/qipowl/core/monkeypatches.rb', line 105 def unuglify self.unbowl.unspacefy.uncarriage.strip end |
#un␚ify ⇒ Object
119 120 121 |
# File 'lib/qipowl/core/monkeypatches.rb', line 119 def un␚ify self.gsub(/␚(.*?)␚/, '') end |
#upcase ⇒ Object
12 13 14 |
# File 'lib/qipowl/utils/unicode_strings.rb', line 12 def upcase Unicode::upcase(self) end |
#upcase! ⇒ Object
15 16 17 |
# File 'lib/qipowl/utils/unicode_strings.rb', line 15 def upcase! self.replace upcase end |
#vacant? ⇒ Boolean
65 66 67 |
# File 'lib/qipowl/core/monkeypatches.rb', line 65 def vacant? nil? || empty? end |