summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsyeopite <syeopite@syeopite.dev>2024-07-17 12:21:48 -0700
committersyeopite <syeopite@syeopite.dev>2024-07-17 12:21:48 -0700
commitfa50e0abf40f120a021229dfdff0d3aff7f3cfe6 (patch)
tree9531950d1a69311381c06bb74cc4813a7aa83fa5 /src
parent8a90add3106d5dffa1bcd731a69d061844dd890f (diff)
downloadinvidious-fa50e0abf40f120a021229dfdff0d3aff7f3cfe6.tar.gz
invidious-fa50e0abf40f120a021229dfdff0d3aff7f3cfe6.tar.bz2
invidious-fa50e0abf40f120a021229dfdff0d3aff7f3cfe6.zip
Simplify last_node retrieval
Co-authored-by: Samantaz Fox <coding@samantaz.fr>
Diffstat (limited to 'src')
-rw-r--r--src/invidious/comments/content.cr10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/invidious/comments/content.cr b/src/invidious/comments/content.cr
index 3e0d41d7..1f55bfe6 100644
--- a/src/invidious/comments/content.cr
+++ b/src/invidious/comments/content.cr
@@ -14,10 +14,10 @@ def text_to_parsed_content(text : String) : JSON::Any
# { 'text': match, 'navigationEndpoint': { 'urlEndpoint' : 'url': match } }
line.scan(/https?:\/\/[^ ]*/).each do |url_match|
# Retrieve last node and update node without match
- last_node = current_nodes[current_nodes.size - 1].as_h
+ last_node = current_nodes[-1].as_h
splitted_last_node = last_node["text"].as_s.split(url_match[0])
last_node["text"] = JSON.parse(splitted_last_node[0].to_json)
- current_nodes[current_nodes.size - 1] = JSON.parse(last_node.to_json)
+ current_nodes[-1] = JSON.parse(last_node.to_json)
# Create new node with match and navigation infos
current_node = {"text" => url_match[0], "navigationEndpoint" => {"urlEndpoint" => {"url" => url_match[0]}}}
current_nodes << (JSON.parse(current_node.to_json))
@@ -28,9 +28,9 @@ def text_to_parsed_content(text : String) : JSON::Any
# After processing of matches inside line
# Add \n at end of last node for preserve carriage return
- last_node = current_nodes[current_nodes.size - 1].as_h
- last_node["text"] = JSON.parse("#{current_nodes[current_nodes.size - 1]["text"]}\n".to_json)
- current_nodes[current_nodes.size - 1] = JSON.parse(last_node.to_json)
+ last_node = current_nodes[-1].as_h
+ last_node["text"] = JSON.parse("#{last_node["text"]}\n".to_json)
+ current_nodes[-1] = JSON.parse(last_node.to_json)
# Finally add final nodes to nodes returned
current_nodes.each do |node|