code-ruby 3.1.2 → 4.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/code +97 -20
- data/lib/code/concerns/shared.rb +331 -15
- data/lib/code/format.rb +15 -1
- data/lib/code/network.rb +87 -0
- data/lib/code/node/call.rb +79 -2
- data/lib/code/node/call_argument.rb +14 -0
- data/lib/code/node/code.rb +5 -4
- data/lib/code/node/function_parameter.rb +7 -4
- data/lib/code/node/list.rb +29 -1
- data/lib/code/object/base_64.rb +132 -6
- data/lib/code/object/boolean.rb +60 -0
- data/lib/code/object/class.rb +138 -2
- data/lib/code/object/code.rb +111 -3
- data/lib/code/object/context.rb +57 -1
- data/lib/code/object/cryptography.rb +63 -0
- data/lib/code/object/date.rb +13339 -462
- data/lib/code/object/decimal.rb +1725 -0
- data/lib/code/object/dictionary.rb +1790 -11
- data/lib/code/object/duration.rb +28 -0
- data/lib/code/object/function.rb +261 -23
- data/lib/code/object/global.rb +534 -1
- data/lib/code/object/html.rb +179 -7
- data/lib/code/object/http.rb +244 -14
- data/lib/code/object/ics.rb +75 -13
- data/lib/code/object/identifier_list.rb +17 -2
- data/lib/code/object/integer.rb +1937 -2
- data/lib/code/object/json.rb +75 -1
- data/lib/code/object/list.rb +3383 -10
- data/lib/code/object/nothing.rb +53 -0
- data/lib/code/object/number.rb +110 -0
- data/lib/code/object/parameter.rb +140 -0
- data/lib/code/object/range.rb +576 -14
- data/lib/code/object/smtp.rb +95 -12
- data/lib/code/object/string.rb +944 -3
- data/lib/code/object/super.rb +10 -1
- data/lib/code/object/time.rb +13358 -498
- data/lib/code/object/url.rb +65 -0
- data/lib/code/object.rb +543 -0
- data/lib/code/parser.rb +161 -24
- data/lib/code-ruby.rb +3 -0
- data/lib/code.rb +30 -3
- metadata +135 -84
- data/.github/dependabot.yml +0 -15
- data/.github/workflows/ci.yml +0 -38
- data/.gitignore +0 -30
- data/.node-version +0 -1
- data/.npm-version +0 -1
- data/.prettierignore +0 -2
- data/.rspec +0 -1
- data/.rubocop.yml +0 -140
- data/.ruby-version +0 -1
- data/.tool-versions +0 -3
- data/AGENTS.md +0 -43
- data/Gemfile +0 -22
- data/Gemfile.lock +0 -292
- data/Rakefile +0 -5
- data/bin/bundle +0 -123
- data/bin/bundle-audit +0 -31
- data/bin/bundler-audit +0 -31
- data/bin/dorian +0 -31
- data/bin/rspec +0 -31
- data/bin/rubocop +0 -31
- data/bin/test +0 -5
- data/code-ruby.gemspec +0 -34
- data/docs/precedence.txt +0 -36
- data/package-lock.json +0 -14
- data/package.json +0 -7
- data/spec/bin/code_spec.rb +0 -48
- data/spec/code/format_spec.rb +0 -153
- data/spec/code/node/call_spec.rb +0 -11
- data/spec/code/object/boolean_spec.rb +0 -18
- data/spec/code/object/cryptography_spec.rb +0 -25
- data/spec/code/object/decimal_spec.rb +0 -50
- data/spec/code/object/dictionary_spec.rb +0 -98
- data/spec/code/object/function_spec.rb +0 -268
- data/spec/code/object/http_spec.rb +0 -33
- data/spec/code/object/ics_spec.rb +0 -50
- data/spec/code/object/integer_spec.rb +0 -42
- data/spec/code/object/list_spec.rb +0 -22
- data/spec/code/object/nothing_spec.rb +0 -14
- data/spec/code/object/range_spec.rb +0 -23
- data/spec/code/object/string_spec.rb +0 -26
- data/spec/code/parser/boolean_spec.rb +0 -11
- data/spec/code/parser/chained_call_spec.rb +0 -16
- data/spec/code/parser/dictionary_spec.rb +0 -18
- data/spec/code/parser/function_spec.rb +0 -16
- data/spec/code/parser/group_spec.rb +0 -11
- data/spec/code/parser/if_modifier_spec.rb +0 -18
- data/spec/code/parser/list_spec.rb +0 -17
- data/spec/code/parser/number_spec.rb +0 -11
- data/spec/code/parser/string_spec.rb +0 -20
- data/spec/code/parser_spec.rb +0 -52
- data/spec/code/type_spec.rb +0 -21
- data/spec/code_spec.rb +0 -717
- data/spec/spec_helper.rb +0 -21
- data/spec/zeitwerk/loader_spec.rb +0 -7
data/lib/code/object/string.rb
CHANGED
|
@@ -3,6 +3,524 @@
|
|
|
3
3
|
class Code
|
|
4
4
|
class Object
|
|
5
5
|
class String < Object
|
|
6
|
+
CLASS_DOCUMENTATION = {
|
|
7
|
+
name: "String",
|
|
8
|
+
description: "represents text and provides parsing, search, and transformation operations.",
|
|
9
|
+
examples: [
|
|
10
|
+
"\"hello\"",
|
|
11
|
+
":hello.upcase",
|
|
12
|
+
"\"a,b\".split(\",\")"
|
|
13
|
+
]
|
|
14
|
+
}.freeze
|
|
15
|
+
INSTANCE_FUNCTIONS = {
|
|
16
|
+
"&" => {
|
|
17
|
+
name: "&",
|
|
18
|
+
description: "returns a function that calls the named selector.",
|
|
19
|
+
examples: ["&\"to_string\"", "&\"upcase\"", "&\"value\""]
|
|
20
|
+
},
|
|
21
|
+
"to_function" => {
|
|
22
|
+
name: "to_function",
|
|
23
|
+
description: "returns a function that calls the named selector.",
|
|
24
|
+
examples: [
|
|
25
|
+
"\"to_string\".to_function",
|
|
26
|
+
"\"upcase\".to_function",
|
|
27
|
+
"\"value\".to_function"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"*" => {
|
|
31
|
+
name: "*",
|
|
32
|
+
description: "returns the string repeated a number of times.",
|
|
33
|
+
examples: ["\"a\" * 3", "\":\" * 2", "\"ab\" * 2"]
|
|
34
|
+
},
|
|
35
|
+
"+" => {
|
|
36
|
+
name: "+",
|
|
37
|
+
description: "returns the string with another value appended.",
|
|
38
|
+
examples: ["\"a\" + \"b\"", "\"count: \" + 1", "\":\" + :ok"]
|
|
39
|
+
},
|
|
40
|
+
"downcase" => {
|
|
41
|
+
name: "downcase",
|
|
42
|
+
description: "returns the string converted to lowercase.",
|
|
43
|
+
examples: ["\"HELLO\".downcase", "\"Code\".downcase", "\"A1\".downcase"]
|
|
44
|
+
},
|
|
45
|
+
"lower_case" => {
|
|
46
|
+
name: "lower_case",
|
|
47
|
+
description: "returns the string converted to lowercase.",
|
|
48
|
+
examples: [
|
|
49
|
+
"\"HELLO\".lower_case",
|
|
50
|
+
"\"Code\".lower_case",
|
|
51
|
+
"\"A1\".lower_case"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"include?" => {
|
|
55
|
+
name: "include?",
|
|
56
|
+
description: "returns whether the string includes another string.",
|
|
57
|
+
examples: [
|
|
58
|
+
"\"hello\".include?(\"ell\")",
|
|
59
|
+
"\"hello\".include?(\"x\")",
|
|
60
|
+
"\":name\".include?(\":\")"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"member?" => {
|
|
64
|
+
name: "member?",
|
|
65
|
+
description: "returns whether the string includes another string.",
|
|
66
|
+
examples: [
|
|
67
|
+
"\"hello\".member?(\"ell\")",
|
|
68
|
+
"\"hello\".member?(\"x\")",
|
|
69
|
+
"\":name\".member?(\":\")"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"starts_with?" => {
|
|
73
|
+
name: "starts_with?",
|
|
74
|
+
description: "returns whether the string starts with another string.",
|
|
75
|
+
examples: [
|
|
76
|
+
"\"hello\".starts_with?(\"he\")",
|
|
77
|
+
"\"hello\".starts_with?(\"lo\")",
|
|
78
|
+
"\":name\".starts_with?(\":\")"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
"start_with?" => {
|
|
82
|
+
name: "start_with?",
|
|
83
|
+
description: "returns whether the string starts with another string.",
|
|
84
|
+
examples: [
|
|
85
|
+
"\"hello\".start_with?(\"he\")",
|
|
86
|
+
"\"hello\".start_with?(\"lo\")",
|
|
87
|
+
"\":name\".start_with?(\":\")"
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
"ends_with?" => {
|
|
91
|
+
name: "ends_with?",
|
|
92
|
+
description: "returns whether the string ends with another string.",
|
|
93
|
+
examples: [
|
|
94
|
+
"\"hello\".ends_with?(\"lo\")",
|
|
95
|
+
"\"hello\".ends_with?(\"he\")",
|
|
96
|
+
"\"file.rb\".ends_with?(\".rb\")"
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
"end_with?" => {
|
|
100
|
+
name: "end_with?",
|
|
101
|
+
description: "returns whether the string ends with another string.",
|
|
102
|
+
examples: [
|
|
103
|
+
"\"hello\".end_with?(\"lo\")",
|
|
104
|
+
"\"hello\".end_with?(\"he\")",
|
|
105
|
+
"\"file.rb\".end_with?(\".rb\")"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"[]" => {
|
|
109
|
+
name: "[]",
|
|
110
|
+
description: "returns the character at an index.",
|
|
111
|
+
examples: ["\"abc\"[0]", "\"abc\"[1]", "\"abc\"[2]"]
|
|
112
|
+
},
|
|
113
|
+
"at" => {
|
|
114
|
+
name: "at",
|
|
115
|
+
description: "returns the character at an index.",
|
|
116
|
+
examples: ["\"abc\".at(0)", "\"abc\".at(1)", "\"abc\".at(2)"]
|
|
117
|
+
},
|
|
118
|
+
"get" => {
|
|
119
|
+
name: "get",
|
|
120
|
+
description: "returns the character at an index.",
|
|
121
|
+
examples: ["\"abc\".get(0)", "\"abc\".get(1)", "\"abc\".get(2)"]
|
|
122
|
+
},
|
|
123
|
+
"capitalize" => {
|
|
124
|
+
name: "capitalize",
|
|
125
|
+
description: "returns the string with its first character capitalized.",
|
|
126
|
+
examples: [
|
|
127
|
+
"\"hello\".capitalize",
|
|
128
|
+
"\"code\".capitalize",
|
|
129
|
+
"\"already\".capitalize"
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"characters" => {
|
|
133
|
+
name: "characters",
|
|
134
|
+
description: "returns the string characters as a list.",
|
|
135
|
+
examples: ["\"abc\".characters", "\"hi\".characters", "\"\".characters"]
|
|
136
|
+
},
|
|
137
|
+
"bytes" => {
|
|
138
|
+
name: "bytes",
|
|
139
|
+
description: "returns the string bytes as a list.",
|
|
140
|
+
examples: ["\"abc\".bytes", "\"A\".bytes", "\"\".bytes"]
|
|
141
|
+
},
|
|
142
|
+
"bytesize" => {
|
|
143
|
+
name: "bytesize",
|
|
144
|
+
description: "returns the number of bytes in the string.",
|
|
145
|
+
examples: ["\"abc\".bytesize", "\"A\".bytesize", "\"\".bytesize"]
|
|
146
|
+
},
|
|
147
|
+
"byte_slice" => {
|
|
148
|
+
name: "byte_slice",
|
|
149
|
+
description: "returns a byte slice from the string.",
|
|
150
|
+
examples: [
|
|
151
|
+
"\"abc\".byte_slice(0)",
|
|
152
|
+
"\"abc\".byte_slice(0, 2)",
|
|
153
|
+
"\"hello\".byte_slice(1, 3)"
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
"codepoints" => {
|
|
157
|
+
name: "codepoints",
|
|
158
|
+
description: "returns the string codepoints as a list.",
|
|
159
|
+
examples: ["\"abc\".codepoints", "\"A\".codepoints", "\"\".codepoints"]
|
|
160
|
+
},
|
|
161
|
+
"character_code_at" => {
|
|
162
|
+
name: "character_code_at",
|
|
163
|
+
description: "returns the codepoint at an index.",
|
|
164
|
+
examples: [
|
|
165
|
+
"\"abc\".character_code_at(0)",
|
|
166
|
+
"\"abc\".character_code_at(1)",
|
|
167
|
+
"\"abc\".character_code_at"
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
"ordinal" => {
|
|
171
|
+
name: "ordinal",
|
|
172
|
+
description: "returns the codepoint for the first character.",
|
|
173
|
+
examples: ["\"a\".ordinal", "\"A\".ordinal", "\"1\".ordinal"]
|
|
174
|
+
},
|
|
175
|
+
"chomp" => {
|
|
176
|
+
name: "chomp",
|
|
177
|
+
description: "returns the string with a trailing record separator removed.",
|
|
178
|
+
examples: ["\"a\\n\".chomp", "\"a\".chomp", "\"a\\r\\n\".chomp"]
|
|
179
|
+
},
|
|
180
|
+
"chop" => {
|
|
181
|
+
name: "chop",
|
|
182
|
+
description: "returns the string with its last character removed.",
|
|
183
|
+
examples: ["\"abc\".chop", "\"a\".chop", "\"\".chop"]
|
|
184
|
+
},
|
|
185
|
+
"delete" => {
|
|
186
|
+
name: "delete",
|
|
187
|
+
description: "returns the string with matching characters removed.",
|
|
188
|
+
examples: [
|
|
189
|
+
"\"hello\".delete(\"l\")",
|
|
190
|
+
"\"123\".delete(\"2\")",
|
|
191
|
+
"\"abc\".delete(\"z\")"
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
"delete_prefix" => {
|
|
195
|
+
name: "delete_prefix",
|
|
196
|
+
description: "returns the string with a matching prefix removed.",
|
|
197
|
+
examples: [
|
|
198
|
+
"\"hello\".delete_prefix(\"he\")",
|
|
199
|
+
"\"hello\".delete_prefix(\"x\")",
|
|
200
|
+
"\"file.rb\".delete_prefix(\"file\")"
|
|
201
|
+
]
|
|
202
|
+
},
|
|
203
|
+
"delete_suffix" => {
|
|
204
|
+
name: "delete_suffix",
|
|
205
|
+
description: "returns the string with a matching suffix removed.",
|
|
206
|
+
examples: [
|
|
207
|
+
"\"hello\".delete_suffix(\"lo\")",
|
|
208
|
+
"\"hello\".delete_suffix(\"x\")",
|
|
209
|
+
"\"file.rb\".delete_suffix(\".rb\")"
|
|
210
|
+
]
|
|
211
|
+
},
|
|
212
|
+
"empty?" => {
|
|
213
|
+
name: "empty?",
|
|
214
|
+
description: "returns whether the string is empty.",
|
|
215
|
+
examples: ["\"\".empty?", "\"a\".empty?", "\" \".empty?"]
|
|
216
|
+
},
|
|
217
|
+
"clear" => {
|
|
218
|
+
name: "clear",
|
|
219
|
+
description: "empties the string and returns it.",
|
|
220
|
+
examples: ["\"abc\".clear", "\"a\".clear", "\"\".clear"]
|
|
221
|
+
},
|
|
222
|
+
"count" => {
|
|
223
|
+
name: "count",
|
|
224
|
+
description: "returns the count of matching characters.",
|
|
225
|
+
examples: [
|
|
226
|
+
"\"hello\".count(\"l\")",
|
|
227
|
+
"\"banana\".count(\"a\")",
|
|
228
|
+
"\"abc\".count(\"z\")"
|
|
229
|
+
]
|
|
230
|
+
},
|
|
231
|
+
"insert" => {
|
|
232
|
+
name: "insert",
|
|
233
|
+
description: "inserts a value at an index and returns the string.",
|
|
234
|
+
examples: [
|
|
235
|
+
"\"ac\".insert(1, \"b\")",
|
|
236
|
+
"\"bc\".insert(0, \"a\")",
|
|
237
|
+
"\"ab\".insert(2, \"c\")"
|
|
238
|
+
]
|
|
239
|
+
},
|
|
240
|
+
"prepend" => {
|
|
241
|
+
name: "prepend",
|
|
242
|
+
description: "prepends a value and returns the string.",
|
|
243
|
+
examples: [
|
|
244
|
+
"\"b\".prepend(\"a\")",
|
|
245
|
+
"\"world\".prepend(\"hello \")",
|
|
246
|
+
"\"1\".prepend(0)"
|
|
247
|
+
]
|
|
248
|
+
},
|
|
249
|
+
"concat" => {
|
|
250
|
+
name: "concat",
|
|
251
|
+
description: "appends values and returns the string.",
|
|
252
|
+
examples: [
|
|
253
|
+
"\"a\".concat(\"b\")",
|
|
254
|
+
"\"a\".concat(\"b\", \"c\")",
|
|
255
|
+
"\"count\".concat(1)"
|
|
256
|
+
]
|
|
257
|
+
},
|
|
258
|
+
"first" => {
|
|
259
|
+
name: "first",
|
|
260
|
+
description: "returns the first character or first characters.",
|
|
261
|
+
examples: ["\"abc\".first", "\"abc\".first(2)", "\"\".first"]
|
|
262
|
+
},
|
|
263
|
+
"index" => {
|
|
264
|
+
name: "index",
|
|
265
|
+
description: "returns the index of a matching substring.",
|
|
266
|
+
examples: [
|
|
267
|
+
"\"hello\".index(\"l\")",
|
|
268
|
+
"\"hello\".index(\"x\")",
|
|
269
|
+
"\"banana\".index(\"na\")"
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
"last" => {
|
|
273
|
+
name: "last",
|
|
274
|
+
description: "returns the last character or last characters.",
|
|
275
|
+
examples: ["\"abc\".last", "\"ab\".last", "\"\".last"]
|
|
276
|
+
},
|
|
277
|
+
"lines" => {
|
|
278
|
+
name: "lines",
|
|
279
|
+
description: "returns the string lines as a list.",
|
|
280
|
+
examples: ["\"a\\nb\".lines", "\"a\".lines", "\"\".lines"]
|
|
281
|
+
},
|
|
282
|
+
"reverse" => {
|
|
283
|
+
name: "reverse",
|
|
284
|
+
description: "returns the string with characters reversed.",
|
|
285
|
+
examples: ["\"abc\".reverse", "\"ab\".reverse", "\"\".reverse"]
|
|
286
|
+
},
|
|
287
|
+
"right_index" => {
|
|
288
|
+
name: "right_index",
|
|
289
|
+
description: "returns the last index of a matching substring.",
|
|
290
|
+
examples: [
|
|
291
|
+
"\"hello\".right_index(\"l\")",
|
|
292
|
+
"\"hello\".right_index(\"x\")",
|
|
293
|
+
"\"banana\".right_index(\"na\")"
|
|
294
|
+
]
|
|
295
|
+
},
|
|
296
|
+
"parameterize" => {
|
|
297
|
+
name: "parameterize",
|
|
298
|
+
description: "returns the string parameterized for identifiers or urls.",
|
|
299
|
+
examples: [
|
|
300
|
+
"\"Hello world\".parameterize",
|
|
301
|
+
"\"a b c\".parameterize",
|
|
302
|
+
"\"Code Ruby\".parameterize"
|
|
303
|
+
]
|
|
304
|
+
},
|
|
305
|
+
"squish" => {
|
|
306
|
+
name: "squish",
|
|
307
|
+
description: "returns the string with surrounding and repeated whitespace collapsed.",
|
|
308
|
+
examples: [
|
|
309
|
+
"\" hello world \".squish",
|
|
310
|
+
"\"a\\n b\".squish",
|
|
311
|
+
"\"a b\".squish"
|
|
312
|
+
]
|
|
313
|
+
},
|
|
314
|
+
"squeeze" => {
|
|
315
|
+
name: "squeeze",
|
|
316
|
+
description: "returns the string with repeated characters collapsed.",
|
|
317
|
+
examples: [
|
|
318
|
+
"\"hellooo\".squeeze",
|
|
319
|
+
"\"book\".squeeze(\"o\")",
|
|
320
|
+
"\"aaab\".squeeze"
|
|
321
|
+
]
|
|
322
|
+
},
|
|
323
|
+
"substitute" => {
|
|
324
|
+
name: "substitute",
|
|
325
|
+
description: "returns the string with the first match replaced.",
|
|
326
|
+
examples: [
|
|
327
|
+
"\"hello\".substitute(\"l\", \"x\")",
|
|
328
|
+
"\"abc\".substitute(\"a\", \"z\")",
|
|
329
|
+
"\"abc\".substitute(\"x\", \"z\")"
|
|
330
|
+
]
|
|
331
|
+
},
|
|
332
|
+
"substitute!" => {
|
|
333
|
+
name: "substitute!",
|
|
334
|
+
description: "replaces the first match in the string and returns it.",
|
|
335
|
+
examples: [
|
|
336
|
+
"\"hello\".substitute!(\"l\", \"x\")",
|
|
337
|
+
"\"abc\".substitute!(\"a\", \"z\")",
|
|
338
|
+
"\"abc\".substitute!(\"x\", \"z\")"
|
|
339
|
+
]
|
|
340
|
+
},
|
|
341
|
+
"substitute_all" => {
|
|
342
|
+
name: "substitute_all",
|
|
343
|
+
description: "returns the string with all matches replaced.",
|
|
344
|
+
examples: [
|
|
345
|
+
"\"hello\".substitute_all(\"l\", \"x\")",
|
|
346
|
+
"\"abcabc\".substitute_all(\"a\", \"z\")",
|
|
347
|
+
"\"abc\".substitute_all(\"x\", \"z\")"
|
|
348
|
+
]
|
|
349
|
+
},
|
|
350
|
+
"substitute_all!" => {
|
|
351
|
+
name: "substitute_all!",
|
|
352
|
+
description: "replaces all matches in the string and returns it.",
|
|
353
|
+
examples: [
|
|
354
|
+
"\"hello\".substitute_all!(\"l\", \"x\")",
|
|
355
|
+
"\"abcabc\".substitute_all!(\"a\", \"z\")",
|
|
356
|
+
"\"abc\".substitute_all!(\"x\", \"z\")"
|
|
357
|
+
]
|
|
358
|
+
},
|
|
359
|
+
"substitute_once" => {
|
|
360
|
+
name: "substitute_once",
|
|
361
|
+
description: "returns the string with the first match replaced.",
|
|
362
|
+
examples: [
|
|
363
|
+
"\"hello\".substitute_once(\"l\", \"x\")",
|
|
364
|
+
"\"abc\".substitute_once(\"a\", \"z\")",
|
|
365
|
+
"\"abc\".substitute_once(\"x\", \"z\")"
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
"substitute_once!" => {
|
|
369
|
+
name: "substitute_once!",
|
|
370
|
+
description: "replaces the first match in the string and returns it.",
|
|
371
|
+
examples: [
|
|
372
|
+
"\"hello\".substitute_once!(\"l\", \"x\")",
|
|
373
|
+
"\"abc\".substitute_once!(\"a\", \"z\")",
|
|
374
|
+
"\"abc\".substitute_once!(\"x\", \"z\")"
|
|
375
|
+
]
|
|
376
|
+
},
|
|
377
|
+
"swapcase" => {
|
|
378
|
+
name: "swapcase",
|
|
379
|
+
description: "returns the string with letter case swapped.",
|
|
380
|
+
examples: ["\"AbC\".swapcase", "\"hello\".swapcase", "\"ABC\".swapcase"]
|
|
381
|
+
},
|
|
382
|
+
"titleize" => {
|
|
383
|
+
name: "titleize",
|
|
384
|
+
description: "returns the string converted to title case.",
|
|
385
|
+
examples: [
|
|
386
|
+
"\"hello world\".titleize",
|
|
387
|
+
"\"code ruby\".titleize",
|
|
388
|
+
"\"one\".titleize"
|
|
389
|
+
]
|
|
390
|
+
},
|
|
391
|
+
"upcase" => {
|
|
392
|
+
name: "upcase",
|
|
393
|
+
description: "returns the string converted to uppercase.",
|
|
394
|
+
examples: ["\"hello\".upcase", "\"Code\".upcase", "\"a1\".upcase"]
|
|
395
|
+
},
|
|
396
|
+
"upper_case" => {
|
|
397
|
+
name: "upper_case",
|
|
398
|
+
description: "returns the string converted to uppercase.",
|
|
399
|
+
examples: [
|
|
400
|
+
"\"hello\".upper_case",
|
|
401
|
+
"\"Code\".upper_case",
|
|
402
|
+
"\"a1\".upper_case"
|
|
403
|
+
]
|
|
404
|
+
},
|
|
405
|
+
"size" => {
|
|
406
|
+
name: "size",
|
|
407
|
+
description: "returns the number of characters in the string.",
|
|
408
|
+
examples: ["\"abc\".size", "\"\".size", "\"hello\".size"]
|
|
409
|
+
},
|
|
410
|
+
"length" => {
|
|
411
|
+
name: "length",
|
|
412
|
+
description: "returns the number of characters in the string.",
|
|
413
|
+
examples: ["\"abc\".length", "\"\".length", "\"hello\".length"]
|
|
414
|
+
},
|
|
415
|
+
"strip" => {
|
|
416
|
+
name: "strip",
|
|
417
|
+
description: "returns the string with surrounding whitespace removed.",
|
|
418
|
+
examples: ["\" a \".strip", "\"\\na\".strip", "\"a\".strip"]
|
|
419
|
+
},
|
|
420
|
+
"left_strip" => {
|
|
421
|
+
name: "left_strip",
|
|
422
|
+
description: "returns the string with leading whitespace removed.",
|
|
423
|
+
examples: ["\" a\".left_strip", "\"\\na\".left_strip", "\"a\".left_strip"]
|
|
424
|
+
},
|
|
425
|
+
"right_strip" => {
|
|
426
|
+
name: "right_strip",
|
|
427
|
+
description: "returns the string with trailing whitespace removed.",
|
|
428
|
+
examples: [
|
|
429
|
+
"\"a \".right_strip",
|
|
430
|
+
"\"a\\n\".right_strip",
|
|
431
|
+
"\"a\".right_strip"
|
|
432
|
+
]
|
|
433
|
+
},
|
|
434
|
+
"slice" => {
|
|
435
|
+
name: "slice",
|
|
436
|
+
description: "returns a slice from the string.",
|
|
437
|
+
examples: ["\"abc\".slice(0)", "\"abc\".slice(0, 2)", "\"abc\".slice(1)"]
|
|
438
|
+
},
|
|
439
|
+
"left_justify" => {
|
|
440
|
+
name: "left_justify",
|
|
441
|
+
description: "returns the string left-justified to a width.",
|
|
442
|
+
examples: [
|
|
443
|
+
"\"a\".left_justify(3)",
|
|
444
|
+
"\"a\".left_justify(3, \".\")",
|
|
445
|
+
"\"abc\".left_justify(2)"
|
|
446
|
+
]
|
|
447
|
+
},
|
|
448
|
+
"right_justify" => {
|
|
449
|
+
name: "right_justify",
|
|
450
|
+
description: "returns the string right-justified to a width.",
|
|
451
|
+
examples: [
|
|
452
|
+
"\"a\".right_justify(3)",
|
|
453
|
+
"\"a\".right_justify(3, \".\")",
|
|
454
|
+
"\"abc\".right_justify(2)"
|
|
455
|
+
]
|
|
456
|
+
},
|
|
457
|
+
"center" => {
|
|
458
|
+
name: "center",
|
|
459
|
+
description: "returns the string centered within a width.",
|
|
460
|
+
examples: [
|
|
461
|
+
"\"a\".center(3)",
|
|
462
|
+
"\"a\".center(3, \".\")",
|
|
463
|
+
"\"abc\".center(2)"
|
|
464
|
+
]
|
|
465
|
+
},
|
|
466
|
+
"pad_start" => {
|
|
467
|
+
name: "pad_start",
|
|
468
|
+
description: "returns the string padded at the beginning.",
|
|
469
|
+
examples: [
|
|
470
|
+
"\"a\".pad_start(3)",
|
|
471
|
+
"\"a\".pad_start(3, \"0\")",
|
|
472
|
+
"\"abc\".pad_start(2)"
|
|
473
|
+
]
|
|
474
|
+
},
|
|
475
|
+
"pad_end" => {
|
|
476
|
+
name: "pad_end",
|
|
477
|
+
description: "returns the string padded at the end.",
|
|
478
|
+
examples: [
|
|
479
|
+
"\"a\".pad_end(3)",
|
|
480
|
+
"\"a\".pad_end(3, \"0\")",
|
|
481
|
+
"\"abc\".pad_end(2)"
|
|
482
|
+
]
|
|
483
|
+
},
|
|
484
|
+
"repeat" => {
|
|
485
|
+
name: "repeat",
|
|
486
|
+
description: "returns the string repeated a number of times.",
|
|
487
|
+
examples: ["\"a\".repeat(3)", "\":\".repeat(2)", "\"ab\".repeat(2)"]
|
|
488
|
+
},
|
|
489
|
+
"substring" => {
|
|
490
|
+
name: "substring",
|
|
491
|
+
description: "returns a substring from the string.",
|
|
492
|
+
examples: [
|
|
493
|
+
"\"abc\".substring(0)",
|
|
494
|
+
"\"abc\".substring(0, 2)",
|
|
495
|
+
"\"hello\".substring(1, 3)"
|
|
496
|
+
]
|
|
497
|
+
},
|
|
498
|
+
"split" => {
|
|
499
|
+
name: "split",
|
|
500
|
+
description: "returns the string split into a list.",
|
|
501
|
+
examples: [
|
|
502
|
+
"\"a,b\".split(\",\")",
|
|
503
|
+
"\"a b\".split",
|
|
504
|
+
"\"a--b\".split(\"--\")"
|
|
505
|
+
]
|
|
506
|
+
},
|
|
507
|
+
"words" => {
|
|
508
|
+
name: "words",
|
|
509
|
+
description: "returns the words in the string as a list.",
|
|
510
|
+
examples: [
|
|
511
|
+
"\"hello world\".words",
|
|
512
|
+
"\"one two\".words",
|
|
513
|
+
"\"\".words"
|
|
514
|
+
]
|
|
515
|
+
}
|
|
516
|
+
}.freeze
|
|
517
|
+
|
|
518
|
+
def self.function_documentation(scope)
|
|
519
|
+
return INSTANCE_FUNCTIONS if scope == :instance
|
|
520
|
+
|
|
521
|
+
{}
|
|
522
|
+
end
|
|
523
|
+
|
|
6
524
|
def initialize(*args, **_kargs, &_block)
|
|
7
525
|
self.raw =
|
|
8
526
|
if args.first.is_an?(Class)
|
|
@@ -37,7 +555,10 @@ class Code
|
|
|
37
555
|
when "downcase"
|
|
38
556
|
sig(args)
|
|
39
557
|
code_downcase
|
|
40
|
-
when "
|
|
558
|
+
when "lower_case"
|
|
559
|
+
sig(args)
|
|
560
|
+
code_lower_case
|
|
561
|
+
when "include?", "member?"
|
|
41
562
|
sig(args) { String }
|
|
42
563
|
code_include?(code_value)
|
|
43
564
|
when "starts_with?"
|
|
@@ -52,30 +573,165 @@ class Code
|
|
|
52
573
|
when "end_with?"
|
|
53
574
|
sig(args) { String }
|
|
54
575
|
code_end_with?(code_value)
|
|
576
|
+
when "[]", "at", "get"
|
|
577
|
+
sig(args) { Integer }
|
|
578
|
+
code_get(code_value)
|
|
579
|
+
when "capitalize"
|
|
580
|
+
sig(args)
|
|
581
|
+
code_capitalize
|
|
582
|
+
when "characters"
|
|
583
|
+
sig(args)
|
|
584
|
+
code_characters
|
|
585
|
+
when "bytes"
|
|
586
|
+
sig(args)
|
|
587
|
+
code_bytes
|
|
588
|
+
when "bytesize"
|
|
589
|
+
sig(args)
|
|
590
|
+
code_bytesize
|
|
591
|
+
when "byte_slice"
|
|
592
|
+
sig(args) { [Integer, Integer.maybe] }
|
|
593
|
+
code_byte_slice(*code_arguments.raw)
|
|
594
|
+
when "codepoints"
|
|
595
|
+
sig(args)
|
|
596
|
+
code_codepoints
|
|
597
|
+
when "character_code_at"
|
|
598
|
+
sig(args) { Integer.maybe }
|
|
599
|
+
code_character_code_at(code_value)
|
|
600
|
+
when "ordinal"
|
|
601
|
+
sig(args)
|
|
602
|
+
code_ordinal
|
|
603
|
+
when "chomp"
|
|
604
|
+
sig(args)
|
|
605
|
+
code_chomp
|
|
606
|
+
when "chop"
|
|
607
|
+
sig(args)
|
|
608
|
+
code_chop
|
|
609
|
+
when "delete"
|
|
610
|
+
sig(args) { String }
|
|
611
|
+
code_delete(code_value)
|
|
612
|
+
when "delete_prefix"
|
|
613
|
+
sig(args) { String }
|
|
614
|
+
code_delete_prefix(code_value)
|
|
615
|
+
when "delete_suffix"
|
|
616
|
+
sig(args) { String }
|
|
617
|
+
code_delete_suffix(code_value)
|
|
618
|
+
when "empty?"
|
|
619
|
+
sig(args)
|
|
620
|
+
code_empty?
|
|
621
|
+
when "clear"
|
|
622
|
+
sig(args)
|
|
623
|
+
code_clear
|
|
624
|
+
when "count"
|
|
625
|
+
sig(args) { String.repeat(1) }
|
|
626
|
+
code_count(*code_arguments.raw)
|
|
627
|
+
when "insert"
|
|
628
|
+
sig(args) { [Integer, Object] }
|
|
629
|
+
code_insert(*code_arguments.raw)
|
|
630
|
+
when "prepend"
|
|
631
|
+
sig(args) { Object }
|
|
632
|
+
code_prepend(code_value)
|
|
633
|
+
when "concat"
|
|
634
|
+
sig(args) { Object.repeat(1) }
|
|
635
|
+
code_concat(*code_arguments.raw)
|
|
55
636
|
when "first"
|
|
56
637
|
sig(args) { Integer.maybe }
|
|
57
638
|
code_first(code_value)
|
|
639
|
+
when "index"
|
|
640
|
+
sig(args) { String }
|
|
641
|
+
code_index(code_value)
|
|
642
|
+
when "last"
|
|
643
|
+
sig(args) { Integer.maybe }
|
|
644
|
+
code_last(code_value)
|
|
645
|
+
when "lines"
|
|
646
|
+
sig(args)
|
|
647
|
+
code_lines
|
|
58
648
|
when "reverse"
|
|
59
649
|
sig(args)
|
|
60
650
|
code_reverse
|
|
651
|
+
when "right_index"
|
|
652
|
+
sig(args) { String }
|
|
653
|
+
code_right_index(code_value)
|
|
61
654
|
when "parameterize"
|
|
62
655
|
sig(args)
|
|
63
656
|
code_parameterize
|
|
657
|
+
when "squish"
|
|
658
|
+
sig(args)
|
|
659
|
+
code_squish
|
|
660
|
+
when "squeeze"
|
|
661
|
+
sig(args) { String.repeat }
|
|
662
|
+
code_squeeze(*code_arguments.raw)
|
|
64
663
|
when "substitute"
|
|
65
664
|
sig(args) { [String, String.maybe] }
|
|
66
665
|
code_substitute(*code_arguments.raw)
|
|
666
|
+
when "substitute!"
|
|
667
|
+
sig(args) { [String, String.maybe] }
|
|
668
|
+
code_substitute!(*code_arguments.raw)
|
|
669
|
+
when "substitute_all"
|
|
670
|
+
sig(args) { [String, String.maybe] }
|
|
671
|
+
code_substitute_all(*code_arguments.raw)
|
|
672
|
+
when "substitute_all!"
|
|
673
|
+
sig(args) { [String, String.maybe] }
|
|
674
|
+
code_substitute_all!(*code_arguments.raw)
|
|
675
|
+
when "substitute_once"
|
|
676
|
+
sig(args) { [String, String.maybe] }
|
|
677
|
+
code_substitute_once(*code_arguments.raw)
|
|
678
|
+
when "substitute_once!"
|
|
679
|
+
sig(args) { [String, String.maybe] }
|
|
680
|
+
code_substitute_once!(*code_arguments.raw)
|
|
681
|
+
when "swapcase"
|
|
682
|
+
sig(args)
|
|
683
|
+
code_swapcase
|
|
684
|
+
when "titleize"
|
|
685
|
+
sig(args)
|
|
686
|
+
code_titleize
|
|
67
687
|
when "upcase"
|
|
68
688
|
sig(args)
|
|
69
689
|
code_upcase
|
|
70
|
-
when "
|
|
690
|
+
when "upper_case"
|
|
691
|
+
sig(args)
|
|
692
|
+
code_upper_case
|
|
693
|
+
when "size", "length"
|
|
71
694
|
sig(args)
|
|
72
695
|
code_size
|
|
73
696
|
when "strip"
|
|
74
697
|
sig(args)
|
|
75
698
|
code_strip
|
|
699
|
+
when "left_strip"
|
|
700
|
+
sig(args)
|
|
701
|
+
code_left_strip
|
|
702
|
+
when "right_strip"
|
|
703
|
+
sig(args)
|
|
704
|
+
code_right_strip
|
|
705
|
+
when "slice"
|
|
706
|
+
sig(args) { Object.repeat(1) }
|
|
707
|
+
code_slice(*code_arguments.raw)
|
|
708
|
+
when "left_justify"
|
|
709
|
+
sig(args) { [Integer, String.maybe] }
|
|
710
|
+
code_left_justify(*code_arguments.raw)
|
|
711
|
+
when "right_justify"
|
|
712
|
+
sig(args) { [Integer, String.maybe] }
|
|
713
|
+
code_right_justify(*code_arguments.raw)
|
|
714
|
+
when "center"
|
|
715
|
+
sig(args) { [Integer, String.maybe] }
|
|
716
|
+
code_center(*code_arguments.raw)
|
|
717
|
+
when "pad_start"
|
|
718
|
+
sig(args) { [Integer, String.maybe] }
|
|
719
|
+
code_pad_start(*code_arguments.raw)
|
|
720
|
+
when "pad_end"
|
|
721
|
+
sig(args) { [Integer, String.maybe] }
|
|
722
|
+
code_pad_end(*code_arguments.raw)
|
|
723
|
+
when "repeat"
|
|
724
|
+
sig(args) { Integer | Decimal }
|
|
725
|
+
code_repeat(code_value)
|
|
726
|
+
when "substring"
|
|
727
|
+
sig(args) { [Integer.maybe, Integer.maybe] }
|
|
728
|
+
code_substring(*code_arguments.raw)
|
|
76
729
|
when "split"
|
|
77
730
|
sig(args) { String.maybe }
|
|
78
731
|
code_split(code_value)
|
|
732
|
+
when "words"
|
|
733
|
+
sig(args)
|
|
734
|
+
code_words
|
|
79
735
|
else
|
|
80
736
|
super
|
|
81
737
|
end
|
|
@@ -85,20 +741,154 @@ class Code
|
|
|
85
741
|
String.new(raw.downcase)
|
|
86
742
|
end
|
|
87
743
|
|
|
744
|
+
def code_lower_case
|
|
745
|
+
code_downcase
|
|
746
|
+
end
|
|
747
|
+
|
|
88
748
|
def code_upcase
|
|
89
749
|
String.new(raw.upcase)
|
|
90
750
|
end
|
|
91
751
|
|
|
752
|
+
def code_upper_case
|
|
753
|
+
code_upcase
|
|
754
|
+
end
|
|
755
|
+
|
|
756
|
+
def code_capitalize
|
|
757
|
+
String.new(raw.capitalize)
|
|
758
|
+
end
|
|
759
|
+
|
|
760
|
+
def code_characters
|
|
761
|
+
List.new(raw.chars)
|
|
762
|
+
end
|
|
763
|
+
|
|
764
|
+
def code_bytes
|
|
765
|
+
List.new(raw.bytes)
|
|
766
|
+
end
|
|
767
|
+
|
|
768
|
+
def code_bytesize
|
|
769
|
+
Integer.new(raw.bytesize)
|
|
770
|
+
end
|
|
771
|
+
|
|
772
|
+
def code_byte_slice(index, length = nil)
|
|
773
|
+
code_index = index.to_code
|
|
774
|
+
code_length = length.to_code
|
|
775
|
+
value =
|
|
776
|
+
if code_length.nothing?
|
|
777
|
+
raw.byteslice(code_index.raw)
|
|
778
|
+
else
|
|
779
|
+
raw.byteslice(code_index.raw, code_length.raw)
|
|
780
|
+
end
|
|
781
|
+
|
|
782
|
+
value.to_code
|
|
783
|
+
end
|
|
784
|
+
|
|
785
|
+
def code_codepoints
|
|
786
|
+
List.new(raw.codepoints)
|
|
787
|
+
end
|
|
788
|
+
|
|
789
|
+
def code_character_code_at(index = nil)
|
|
790
|
+
code_index = index.to_code
|
|
791
|
+
code_index = Integer.new(0) if code_index.nothing?
|
|
792
|
+
|
|
793
|
+
raw.codepoints[code_index.raw].to_code
|
|
794
|
+
end
|
|
795
|
+
|
|
796
|
+
def code_ordinal
|
|
797
|
+
raw.empty? ? Nothing.new : Integer.new(raw.ord)
|
|
798
|
+
end
|
|
799
|
+
|
|
800
|
+
def code_chomp
|
|
801
|
+
String.new(raw.chomp)
|
|
802
|
+
end
|
|
803
|
+
|
|
804
|
+
def code_chop
|
|
805
|
+
String.new(raw.chop)
|
|
806
|
+
end
|
|
807
|
+
|
|
808
|
+
def code_delete(value)
|
|
809
|
+
code_value = value.to_code
|
|
810
|
+
String.new(raw.delete(code_value.raw))
|
|
811
|
+
end
|
|
812
|
+
|
|
813
|
+
def code_delete_prefix(value)
|
|
814
|
+
code_value = value.to_code
|
|
815
|
+
String.new(raw.delete_prefix(code_value.raw))
|
|
816
|
+
end
|
|
817
|
+
|
|
818
|
+
def code_delete_suffix(value)
|
|
819
|
+
code_value = value.to_code
|
|
820
|
+
String.new(raw.delete_suffix(code_value.raw))
|
|
821
|
+
end
|
|
822
|
+
|
|
823
|
+
def code_empty?
|
|
824
|
+
Boolean.new(raw.empty?)
|
|
825
|
+
end
|
|
826
|
+
|
|
827
|
+
def code_clear
|
|
828
|
+
raw.clear
|
|
829
|
+
self
|
|
830
|
+
end
|
|
831
|
+
|
|
832
|
+
def code_count(*selectors)
|
|
833
|
+
code_selectors = selectors.to_code
|
|
834
|
+
|
|
835
|
+
Integer.new(raw.count(*code_selectors.raw.map(&:to_s)))
|
|
836
|
+
end
|
|
837
|
+
|
|
838
|
+
def code_insert(index, value)
|
|
839
|
+
code_index = index.to_code
|
|
840
|
+
code_value = value.to_code
|
|
841
|
+
|
|
842
|
+
raw.insert(code_index.raw, code_value.to_s)
|
|
843
|
+
self
|
|
844
|
+
end
|
|
845
|
+
|
|
846
|
+
def code_prepend(value)
|
|
847
|
+
code_value = value.to_code
|
|
848
|
+
|
|
849
|
+
raw.prepend(code_value.to_s)
|
|
850
|
+
self
|
|
851
|
+
end
|
|
852
|
+
|
|
853
|
+
def code_concat(*values)
|
|
854
|
+
values.each { |value| raw.concat(value.to_code.to_s) }
|
|
855
|
+
self
|
|
856
|
+
end
|
|
857
|
+
|
|
858
|
+
def code_get(value)
|
|
859
|
+
code_value = value.to_code
|
|
860
|
+
raw[code_value.raw].to_code
|
|
861
|
+
end
|
|
862
|
+
|
|
92
863
|
def code_include?(value)
|
|
93
864
|
code_value = value.to_code
|
|
94
865
|
Boolean.new(raw.include?(code_value.raw))
|
|
95
866
|
end
|
|
96
867
|
|
|
868
|
+
def code_index(value)
|
|
869
|
+
code_value = value.to_code
|
|
870
|
+
raw.index(code_value.raw).to_code
|
|
871
|
+
end
|
|
872
|
+
|
|
873
|
+
def code_last(n = nil)
|
|
874
|
+
code_n = n.to_code
|
|
875
|
+
code_n = Integer.new(1) if code_n.nothing?
|
|
876
|
+
String.new(raw.last(code_n.raw))
|
|
877
|
+
end
|
|
878
|
+
|
|
879
|
+
def code_lines
|
|
880
|
+
List.new(raw.lines)
|
|
881
|
+
end
|
|
882
|
+
|
|
97
883
|
def code_multiplication(other)
|
|
98
884
|
code_other = other.to_code
|
|
99
885
|
String.new(raw * code_other.raw)
|
|
100
886
|
end
|
|
101
887
|
|
|
888
|
+
def code_repeat(other)
|
|
889
|
+
code_multiplication(other)
|
|
890
|
+
end
|
|
891
|
+
|
|
102
892
|
def code_starts_with?(value)
|
|
103
893
|
code_value = value.to_code
|
|
104
894
|
Boolean.new(raw.start_with?(code_value.raw))
|
|
@@ -126,8 +916,34 @@ class Code
|
|
|
126
916
|
String.new(raw.reverse)
|
|
127
917
|
end
|
|
128
918
|
|
|
919
|
+
def code_right_index(value)
|
|
920
|
+
code_value = value.to_code
|
|
921
|
+
raw.rindex(code_value.raw).to_code
|
|
922
|
+
end
|
|
923
|
+
|
|
129
924
|
def code_to_function(**_globals)
|
|
130
|
-
|
|
925
|
+
unless /\A[A-Za-z_][A-Za-z0-9_]*[!?]?\z/.match?(raw)
|
|
926
|
+
raise Error, "String#to_function: invalid function name"
|
|
927
|
+
end
|
|
928
|
+
|
|
929
|
+
Function.new(
|
|
930
|
+
[{ name: "_" }],
|
|
931
|
+
Node::Code.new(
|
|
932
|
+
[
|
|
933
|
+
{
|
|
934
|
+
left_operation: {
|
|
935
|
+
first: { call: { name: "_" } },
|
|
936
|
+
others: [
|
|
937
|
+
{
|
|
938
|
+
operator: ".",
|
|
939
|
+
statement: { call: { name: raw } }
|
|
940
|
+
}
|
|
941
|
+
]
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
]
|
|
945
|
+
)
|
|
946
|
+
)
|
|
131
947
|
end
|
|
132
948
|
|
|
133
949
|
def code_inspect
|
|
@@ -138,13 +954,56 @@ class Code
|
|
|
138
954
|
String.new(raw.parameterize)
|
|
139
955
|
end
|
|
140
956
|
|
|
957
|
+
def code_squish
|
|
958
|
+
String.new(raw.squish)
|
|
959
|
+
end
|
|
960
|
+
|
|
961
|
+
def code_squeeze(*selectors)
|
|
962
|
+
code_selectors = selectors.to_code
|
|
963
|
+
|
|
964
|
+
String.new(raw.squeeze(*code_selectors.raw.map(&:to_s)))
|
|
965
|
+
end
|
|
966
|
+
|
|
141
967
|
def code_substitute(from = nil, to = nil)
|
|
968
|
+
code_substitute_all(from, to)
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
def code_substitute!(from = nil, to = nil)
|
|
972
|
+
code_substitute_all!(from, to)
|
|
973
|
+
end
|
|
974
|
+
|
|
975
|
+
def code_substitute_all(from = nil, to = nil)
|
|
142
976
|
code_from = from.to_code
|
|
143
977
|
code_to = to.to_code
|
|
144
978
|
|
|
145
979
|
String.new(raw.gsub(code_from.to_s, code_to.to_s))
|
|
146
980
|
end
|
|
147
981
|
|
|
982
|
+
def code_substitute_all!(from = nil, to = nil)
|
|
983
|
+
self.raw = code_substitute_all(from, to).raw
|
|
984
|
+
self
|
|
985
|
+
end
|
|
986
|
+
|
|
987
|
+
def code_substitute_once(from = nil, to = nil)
|
|
988
|
+
code_from = from.to_code
|
|
989
|
+
code_to = to.to_code
|
|
990
|
+
|
|
991
|
+
String.new(raw.sub(code_from.to_s, code_to.to_s))
|
|
992
|
+
end
|
|
993
|
+
|
|
994
|
+
def code_substitute_once!(from = nil, to = nil)
|
|
995
|
+
self.raw = code_substitute_once(from, to).raw
|
|
996
|
+
self
|
|
997
|
+
end
|
|
998
|
+
|
|
999
|
+
def code_swapcase
|
|
1000
|
+
String.new(raw.swapcase)
|
|
1001
|
+
end
|
|
1002
|
+
|
|
1003
|
+
def code_titleize
|
|
1004
|
+
String.new(raw.titleize)
|
|
1005
|
+
end
|
|
1006
|
+
|
|
148
1007
|
def code_first(n = nil)
|
|
149
1008
|
code_n = n.to_code
|
|
150
1009
|
code_n = Integer.new(1) if code_n.nothing?
|
|
@@ -163,6 +1022,84 @@ class Code
|
|
|
163
1022
|
String.new(sanitized_utf8_raw.strip)
|
|
164
1023
|
end
|
|
165
1024
|
|
|
1025
|
+
def code_left_strip
|
|
1026
|
+
String.new(raw.lstrip)
|
|
1027
|
+
end
|
|
1028
|
+
|
|
1029
|
+
def code_right_strip
|
|
1030
|
+
String.new(raw.rstrip)
|
|
1031
|
+
end
|
|
1032
|
+
|
|
1033
|
+
def code_slice(*arguments)
|
|
1034
|
+
code_arguments = arguments.to_code.raw
|
|
1035
|
+
|
|
1036
|
+
if code_arguments.first.is_a?(Range)
|
|
1037
|
+
code_range = code_arguments.first
|
|
1038
|
+
range =
|
|
1039
|
+
::Range.new(
|
|
1040
|
+
code_range.code_left.to_i,
|
|
1041
|
+
code_range.code_right.to_i,
|
|
1042
|
+
code_range.exclude_end?
|
|
1043
|
+
)
|
|
1044
|
+
|
|
1045
|
+
return raw.slice(range).to_code
|
|
1046
|
+
end
|
|
1047
|
+
|
|
1048
|
+
raw.slice(*code_arguments.map(&:to_i)).to_code
|
|
1049
|
+
end
|
|
1050
|
+
|
|
1051
|
+
def code_left_justify(width, padding = nil)
|
|
1052
|
+
code_width = width.to_code
|
|
1053
|
+
code_padding = padding.to_code
|
|
1054
|
+
code_padding = String.new(" ") if code_padding.nothing?
|
|
1055
|
+
|
|
1056
|
+
String.new(raw.ljust(code_width.raw, code_padding.to_s))
|
|
1057
|
+
end
|
|
1058
|
+
|
|
1059
|
+
def code_right_justify(width, padding = nil)
|
|
1060
|
+
code_width = width.to_code
|
|
1061
|
+
code_padding = padding.to_code
|
|
1062
|
+
code_padding = String.new(" ") if code_padding.nothing?
|
|
1063
|
+
|
|
1064
|
+
String.new(raw.rjust(code_width.raw, code_padding.to_s))
|
|
1065
|
+
end
|
|
1066
|
+
|
|
1067
|
+
def code_center(width, padding = nil)
|
|
1068
|
+
code_width = width.to_code
|
|
1069
|
+
code_padding = padding.to_code
|
|
1070
|
+
code_padding = String.new(" ") if code_padding.nothing?
|
|
1071
|
+
|
|
1072
|
+
String.new(raw.center(code_width.raw, code_padding.to_s))
|
|
1073
|
+
end
|
|
1074
|
+
|
|
1075
|
+
def code_pad_start(width, padding = nil)
|
|
1076
|
+
code_width = width.to_code
|
|
1077
|
+
code_padding = padding.to_code
|
|
1078
|
+
code_padding = String.new(" ") if code_padding.nothing?
|
|
1079
|
+
|
|
1080
|
+
String.new(raw.rjust(code_width.raw, code_padding.to_s))
|
|
1081
|
+
end
|
|
1082
|
+
|
|
1083
|
+
def code_pad_end(width, padding = nil)
|
|
1084
|
+
code_width = width.to_code
|
|
1085
|
+
code_padding = padding.to_code
|
|
1086
|
+
code_padding = String.new(" ") if code_padding.nothing?
|
|
1087
|
+
|
|
1088
|
+
String.new(raw.ljust(code_width.raw, code_padding.to_s))
|
|
1089
|
+
end
|
|
1090
|
+
|
|
1091
|
+
def code_substring(start = nil, finish = nil)
|
|
1092
|
+
code_start = start.to_code
|
|
1093
|
+
code_finish = finish.to_code
|
|
1094
|
+
start_index = code_start.nothing? ? 0 : code_start.raw
|
|
1095
|
+
finish_index = code_finish.nothing? ? raw.length : code_finish.raw
|
|
1096
|
+
start_index = 0 if start_index.negative?
|
|
1097
|
+
finish_index = 0 if finish_index.negative?
|
|
1098
|
+
start_index, finish_index = finish_index, start_index if start_index > finish_index
|
|
1099
|
+
|
|
1100
|
+
String.new(raw[start_index...finish_index].to_s)
|
|
1101
|
+
end
|
|
1102
|
+
|
|
166
1103
|
def code_split(value)
|
|
167
1104
|
code_value = value.to_code
|
|
168
1105
|
|
|
@@ -173,6 +1110,10 @@ class Code
|
|
|
173
1110
|
end
|
|
174
1111
|
end
|
|
175
1112
|
|
|
1113
|
+
def code_words
|
|
1114
|
+
List.new(raw.split)
|
|
1115
|
+
end
|
|
1116
|
+
|
|
176
1117
|
def present?
|
|
177
1118
|
raw.present?
|
|
178
1119
|
end
|