code-ruby 4.0.0 → 4.0.2

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/code +21 -34
  4. data/lib/code/concerns/shared.rb +103 -99
  5. data/lib/code/format.rb +23 -19
  6. data/lib/code/network.rb +23 -28
  7. data/lib/code/node/call.rb +15 -9
  8. data/lib/code/node/code.rb +5 -5
  9. data/lib/code/node/function.rb +6 -1
  10. data/lib/code/node/left_operation.rb +3 -3
  11. data/lib/code/node/list.rb +10 -8
  12. data/lib/code/node/square_bracket.rb +2 -2
  13. data/lib/code/object/boolean.rb +13 -17
  14. data/lib/code/object/class.rb +33 -27
  15. data/lib/code/object/code.rb +4 -47
  16. data/lib/code/object/context.rb +8 -11
  17. data/lib/code/object/cryptography.rb +12 -6
  18. data/lib/code/object/date.rb +910 -449
  19. data/lib/code/object/decimal.rb +229 -856
  20. data/lib/code/object/dictionary.rb +116 -49
  21. data/lib/code/object/duration.rb +3 -7
  22. data/lib/code/object/function.rb +96 -54
  23. data/lib/code/object/global.rb +122 -209
  24. data/lib/code/object/html.rb +7 -13
  25. data/lib/code/object/http.rb +29 -43
  26. data/lib/code/object/ics.rb +6 -13
  27. data/lib/code/object/identifier_list.rb +16 -11
  28. data/lib/code/object/integer.rb +270 -942
  29. data/lib/code/object/json.rb +8 -28
  30. data/lib/code/object/list.rb +98 -114
  31. data/lib/code/object/nothing.rb +11 -11
  32. data/lib/code/object/number.rb +20 -10
  33. data/lib/code/object/parameter.rb +18 -9
  34. data/lib/code/object/range.rb +62 -108
  35. data/lib/code/object/smtp.rb +20 -15
  36. data/lib/code/object/string.rb +55 -29
  37. data/lib/code/object/super.rb +2 -1
  38. data/lib/code/object/time.rb +1146 -572
  39. data/lib/code/object/url.rb +4 -2
  40. data/lib/code/object.rb +119 -80
  41. data/lib/code/parser.rb +31 -92
  42. data/lib/code.rb +3 -11
  43. metadata +3 -23
@@ -5,12 +5,9 @@ class Code
5
5
  class String < Object
6
6
  CLASS_DOCUMENTATION = {
7
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
- ]
8
+ description:
9
+ "represents text and provides parsing, search, and transformation operations.",
10
+ examples: ["\"hello\"", ":hello.upcase", "\"a,b\".split(\",\")"]
14
11
  }.freeze
15
12
  INSTANCE_FUNCTIONS = {
16
13
  "&" => {
@@ -40,7 +37,11 @@ class Code
40
37
  "downcase" => {
41
38
  name: "downcase",
42
39
  description: "returns the string converted to lowercase.",
43
- examples: ["\"HELLO\".downcase", "\"Code\".downcase", "\"A1\".downcase"]
40
+ examples: [
41
+ "\"HELLO\".downcase",
42
+ "\"Code\".downcase",
43
+ "\"A1\".downcase"
44
+ ]
44
45
  },
45
46
  "lower_case" => {
46
47
  name: "lower_case",
@@ -122,7 +123,8 @@ class Code
122
123
  },
123
124
  "capitalize" => {
124
125
  name: "capitalize",
125
- description: "returns the string with its first character capitalized.",
126
+ description:
127
+ "returns the string with its first character capitalized.",
126
128
  examples: [
127
129
  "\"hello\".capitalize",
128
130
  "\"code\".capitalize",
@@ -132,7 +134,11 @@ class Code
132
134
  "characters" => {
133
135
  name: "characters",
134
136
  description: "returns the string characters as a list.",
135
- examples: ["\"abc\".characters", "\"hi\".characters", "\"\".characters"]
137
+ examples: [
138
+ "\"abc\".characters",
139
+ "\"hi\".characters",
140
+ "\"\".characters"
141
+ ]
136
142
  },
137
143
  "bytes" => {
138
144
  name: "bytes",
@@ -156,7 +162,11 @@ class Code
156
162
  "codepoints" => {
157
163
  name: "codepoints",
158
164
  description: "returns the string codepoints as a list.",
159
- examples: ["\"abc\".codepoints", "\"A\".codepoints", "\"\".codepoints"]
165
+ examples: [
166
+ "\"abc\".codepoints",
167
+ "\"A\".codepoints",
168
+ "\"\".codepoints"
169
+ ]
160
170
  },
161
171
  "character_code_at" => {
162
172
  name: "character_code_at",
@@ -174,7 +184,8 @@ class Code
174
184
  },
175
185
  "chomp" => {
176
186
  name: "chomp",
177
- description: "returns the string with a trailing record separator removed.",
187
+ description:
188
+ "returns the string with a trailing record separator removed.",
178
189
  examples: ["\"a\\n\".chomp", "\"a\".chomp", "\"a\\r\\n\".chomp"]
179
190
  },
180
191
  "chop" => {
@@ -295,7 +306,8 @@ class Code
295
306
  },
296
307
  "parameterize" => {
297
308
  name: "parameterize",
298
- description: "returns the string parameterized for identifiers or urls.",
309
+ description:
310
+ "returns the string parameterized for identifiers or urls.",
299
311
  examples: [
300
312
  "\"Hello world\".parameterize",
301
313
  "\"a b c\".parameterize",
@@ -304,7 +316,8 @@ class Code
304
316
  },
305
317
  "squish" => {
306
318
  name: "squish",
307
- description: "returns the string with surrounding and repeated whitespace collapsed.",
319
+ description:
320
+ "returns the string with surrounding and repeated whitespace collapsed.",
308
321
  examples: [
309
322
  "\" hello world \".squish",
310
323
  "\"a\\n b\".squish",
@@ -377,7 +390,11 @@ class Code
377
390
  "swapcase" => {
378
391
  name: "swapcase",
379
392
  description: "returns the string with letter case swapped.",
380
- examples: ["\"AbC\".swapcase", "\"hello\".swapcase", "\"ABC\".swapcase"]
393
+ examples: [
394
+ "\"AbC\".swapcase",
395
+ "\"hello\".swapcase",
396
+ "\"ABC\".swapcase"
397
+ ]
381
398
  },
382
399
  "titleize" => {
383
400
  name: "titleize",
@@ -414,13 +431,18 @@ class Code
414
431
  },
415
432
  "strip" => {
416
433
  name: "strip",
417
- description: "returns the string with surrounding whitespace removed.",
434
+ description:
435
+ "returns the string with surrounding whitespace removed.",
418
436
  examples: ["\" a \".strip", "\"\\na\".strip", "\"a\".strip"]
419
437
  },
420
438
  "left_strip" => {
421
439
  name: "left_strip",
422
440
  description: "returns the string with leading whitespace removed.",
423
- examples: ["\" a\".left_strip", "\"\\na\".left_strip", "\"a\".left_strip"]
441
+ examples: [
442
+ "\" a\".left_strip",
443
+ "\"\\na\".left_strip",
444
+ "\"a\".left_strip"
445
+ ]
424
446
  },
425
447
  "right_strip" => {
426
448
  name: "right_strip",
@@ -434,7 +456,11 @@ class Code
434
456
  "slice" => {
435
457
  name: "slice",
436
458
  description: "returns a slice from the string.",
437
- examples: ["\"abc\".slice(0)", "\"abc\".slice(0, 2)", "\"abc\".slice(1)"]
459
+ examples: [
460
+ "\"abc\".slice(0)",
461
+ "\"abc\".slice(0, 2)",
462
+ "\"abc\".slice(1)"
463
+ ]
438
464
  },
439
465
  "left_justify" => {
440
466
  name: "left_justify",
@@ -507,11 +533,7 @@ class Code
507
533
  "words" => {
508
534
  name: "words",
509
535
  description: "returns the words in the string as a list.",
510
- examples: [
511
- "\"hello world\".words",
512
- "\"one two\".words",
513
- "\"\".words"
514
- ]
536
+ examples: ["\"hello world\".words", "\"one two\".words", "\"\".words"]
515
537
  }
516
538
  }.freeze
517
539
 
@@ -932,17 +954,20 @@ class Code
932
954
  [
933
955
  {
934
956
  left_operation: {
935
- first: { call: { name: "_" } },
936
- others: [
937
- {
938
- operator: ".",
939
- statement: { call: { name: raw } }
957
+ first: {
958
+ call: {
959
+ name: "_"
940
960
  }
961
+ },
962
+ others: [
963
+ { operator: ".", statement: { call: { name: raw } } }
941
964
  ]
942
965
  }
943
966
  }
944
967
  ]
945
- )
968
+ ),
969
+ nil,
970
+ Global.new
946
971
  )
947
972
  end
948
973
 
@@ -1095,7 +1120,8 @@ class Code
1095
1120
  finish_index = code_finish.nothing? ? raw.length : code_finish.raw
1096
1121
  start_index = 0 if start_index.negative?
1097
1122
  finish_index = 0 if finish_index.negative?
1098
- start_index, finish_index = finish_index, start_index if start_index > finish_index
1123
+ start_index, finish_index = finish_index, start_index if start_index >
1124
+ finish_index
1099
1125
 
1100
1126
  String.new(raw[start_index...finish_index].to_s)
1101
1127
  end
@@ -5,7 +5,8 @@ class Code
5
5
  class Super < Function
6
6
  CLASS_DOCUMENTATION = {
7
7
  name: "Super",
8
- description: "calls the captured parent function available inside an extended function.",
8
+ description:
9
+ "calls the captured parent function available inside an extended function.",
9
10
  examples: [
10
11
  "Base = () => { self.name = :base self } Child = Base.extend(() => { super() }) Child().name",
11
12
  "Base = (name) => { self.name = name self } Child = Base.extend((...) => { super(...) }) Child(:ada).name",