code-ruby 1.9.9 → 1.9.10
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/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/format.rb +30 -0
- data/spec/code/format_spec.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d0ceecc686aef6964768b675a3be83b75127a0b425bd452745ed06101d4cc2b
|
|
4
|
+
data.tar.gz: 5778826718ab6614081ad28e008cd885d2f1c4ddeb303d5fafa87a67befa63d8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 531f8de970b16632012ea7cdb0836974d3333c24f506026e128ad317b02845fb5576c10529d833b8223cbc099366c9bddff96b794595939c7afdf7944b2c02f1
|
|
7
|
+
data.tar.gz: 4ca6148814db2b2e3dce20ccc122f96edbbec1cd1c217ae3700c089159df388b98dbde7e85e897045e136688f0ec9fb2520b02b88b913c7e7dc5a8ca80e359e9
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.9.
|
|
1
|
+
1.9.10
|
data/lib/code/format.rb
CHANGED
|
@@ -394,6 +394,9 @@ class Code
|
|
|
394
394
|
end
|
|
395
395
|
|
|
396
396
|
def format_left_operation(operation, indent:)
|
|
397
|
+
merged_string = extract_string_concatenation_parts(left_operation: operation)
|
|
398
|
+
return format_string(merged_string, indent: indent) if merged_string
|
|
399
|
+
|
|
397
400
|
expression = format_nested_statement(operation[:first], indent: indent)
|
|
398
401
|
|
|
399
402
|
Array(operation[:others]).each do |other|
|
|
@@ -421,6 +424,33 @@ class Code
|
|
|
421
424
|
expression
|
|
422
425
|
end
|
|
423
426
|
|
|
427
|
+
def extract_string_concatenation_parts(statement)
|
|
428
|
+
return nil unless statement.is_a?(Hash)
|
|
429
|
+
|
|
430
|
+
if statement.key?(:string)
|
|
431
|
+
return Array(statement[:string])
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
return nil unless statement.key?(:left_operation)
|
|
435
|
+
|
|
436
|
+
operation = statement[:left_operation]
|
|
437
|
+
others = Array(operation[:others])
|
|
438
|
+
return nil if others.empty?
|
|
439
|
+
return nil unless others.all? { |other| other[:operator] == "+" }
|
|
440
|
+
|
|
441
|
+
parts = extract_string_concatenation_parts(operation[:first])
|
|
442
|
+
return nil unless parts
|
|
443
|
+
|
|
444
|
+
others.each do |other|
|
|
445
|
+
nested = extract_string_concatenation_parts(other[:statement])
|
|
446
|
+
return nil unless nested
|
|
447
|
+
|
|
448
|
+
parts.concat(nested)
|
|
449
|
+
end
|
|
450
|
+
|
|
451
|
+
parts
|
|
452
|
+
end
|
|
453
|
+
|
|
424
454
|
def format_right_operation(operation, indent:)
|
|
425
455
|
operator = operation[:operator].to_s
|
|
426
456
|
left = format_nested_statement(operation[:left], indent: indent)
|
data/spec/code/format_spec.rb
CHANGED
|
@@ -34,6 +34,10 @@ RSpec.describe Code::Format do
|
|
|
34
34
|
[
|
|
35
35
|
"proxy_url = (url) => { \"{proxy_base_url}?{{ url: url, disposition: proxy_inline_disposition }.to_query}\" }",
|
|
36
36
|
"proxy_url = (url) => {\n \"{proxy_base_url}?\"\n + \"{{\n url: url,\n disposition: proxy_inline_disposition\n }.to_query}\"\n}"
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
"x = { content: \"you select the funniest tweets for a french \" + \"audience from the provided candidates. pick up to \" + \"{max_selected}. prioritize genuinely funny content\" + \" (jokes, memes, punchlines, absurd). avoid \" + \"politics/news/serious content. output only json.\" }",
|
|
40
|
+
"x = {\n content: \"you select the funniest tweets for a french \"\n + \"audience from the provided candidates. pick up to \"\n + \"{max_selected}. prioritize genuinely funny content\"\n + \" (jokes, memes, punchlines, absurd). avoid \"\n + \"politics/news/serious content. output only json.\"\n}"
|
|
37
41
|
]
|
|
38
42
|
].each do |input, expected|
|
|
39
43
|
it "formats #{input.inspect}" do
|