ref: 2477ebd2f3a93498ead2b8c37344032919dc841d
parent: 18e623430e9c66ad5f5a0755b4bbd9401d80fe2d
author: 0x4A4D00 <scorpion_rn@yahoo.com>
date: Mon Jul 10 12:33:08 EDT 2023
JSON Parser Test Added
--- a/.idea/Test-IRC.iml
+++ b/.idea/Test-IRC.iml
@@ -11,5 +11,6 @@
</content>
<orderEntry type="jdk" jdkName="ruby-3.2.1-p31" jdkType="RUBY_SDK" />
<orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" scope="PROVIDED" name="net-yail (v1.6.2, ruby-3.2.1-p31) [gem]" level="application" />
</component>
</module>
\ No newline at end of file
--- /dev/null
+++ b/Test_JSON.rb
@@ -1,0 +1,67 @@
+require 'json'
+
+# JSON string to be parsed
+#json_string = 'data:{"name": "John", "age": 30, "city": "New York"}'
+
+# Parse the JSON string
+
+#test = json_string.sub('data:', '')
+
+# parsed_json = JSON.parse(test)
+#
+# # Access the values from the parsed JSON
+# name = parsed_json['name']
+# age = parsed_json['age']
+# city = parsed_json['city']
+#
+# # Output the values
+# puts "Name: #{name}"
+# puts "Age: #{age}"
+# puts "City: #{city}"
+
+
+data_string = 'data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null} data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null}'
+
+# Split the data_string on whitespace followed by "data:" to separate each JSON string
+json_strings = data_string.scan(/data:(\{.*?\})/)
+
+parsed_data = []
+
+json_strings.each do |json_str|
+ # Prepend "data:" to the JSON string since it was removed during splitting
+ # json_str = "data:" + json_str
+
+ # Parse the JSON string
+ parsed_data << JSON.parse(json_str)
+end
+
+# Now you have an array of parsed JSON objects
+parsed_data.each do |data|
+ puts data.inspect
+end
+
+
+
+data_string = 'data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null} data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null}'
+
+m = 'data:{"token":{"id":9856,"text":"Hello","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":12,"text":"!","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":1265,"text":" How","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":418,"text":" can","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":295,"text":" I","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":733,"text":" help","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":299,"text":" you","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":1722,"text":" today","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":42,"text":"?","logprob":0.0,"special":false},"generated_text":null,"details":null}\n'+
+ 'data:{"token":{"id":11,"text":"<|endoftext|>","logprob":0.0,"special":true},"generated_text":"Hello! How can I help you today?","details":null}';
+
+results = data_string.scan(/data:(\{.*?\})/)
+
+parsed_data = results.map { |item| JSON.parse(item[0]) }
+
+parsed_data.each do |data|
+ puts "Name: #{data['token']['text']}"
+ # puts "Age: #{data['age']}"
+ # puts "City: #{data['city']}"
+end
+
--- /dev/null
+++ b/workflows/ruby.yml
@@ -1,0 +1,32 @@
+
+name: Ruby
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+permissions:
+ contents: read
+
+jobs:
+ test:
+
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ ruby-version: ['2.6', '2.7', '3.0']
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Ruby
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
+ # uses: ruby/setup-ruby@v1
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
+ with:
+ ruby-version: ${{ matrix.ruby-version }}
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
+ - name: Run tests
+ run: ruby -r test.rb
\ No newline at end of file