Now I am working on extracting information from a text file in Ruby. Then how can I extract only the number "0.6748984055823062" from the following text file?
{ "sentiment_analysis": [ { "positive": [ { "sentiment": "Popular", "topic": "games", "score": 0.6748984055823062, "original_text": "Popular games", "original_length": 13, "normalized_text": "Popular games", "normalized_length": 13, "offset": 0 }, { "sentiment": "engaging", "topic": "pop culture-inspired games", "score": 0.6280145725181376, "original_text": "engaging pop culture-inspired games", "original_length": 35, "normalized_text": "engaging pop culture-inspired games", "normalized_length": 35, "offset": 370 },
What I tried was that I could read the file and print it line by line with the following code.
counter = 1 file = File.new("Code.org", "r") while (line = file.gets) puts "#{counter}: #{line}" counter = counter + 1 end file.close
I want to set a number to a variable so that I can process it.
source share