Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 507493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:48:36+00:00 2026-05-13T06:48:36+00:00

How can i easily parse a document which has this structure description some line

  • 0

How can i easily parse a document which has this structure

description
some line of text
another line of text
more lines of text

quality
3 47 88 4 4 4  4

text: type 1
stats some funny stats

description
some line of text2
another line of text2
more lines of text2

quality
1 2  4 6 7

text: type 1
stats some funny stats

.
.
.

Ideally i would want an array of hash structures where each hash represents a ‘section’ of the document and probably should look like this:

{:description => “some line of text
another line of text
more lines of text”,
:quality => “3 47 88 4 4 4 4”,
:text =>type 1,
:stats => “some funny stats”}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:48:37+00:00Added an answer on May 13, 2026 at 6:48 am

    You should look for the indicator lines (description, quality, text and stats) in a loop and fill the hash while processing the document line by line.

    Another option would be to use regular expressions and parse the document at once, but you don’t really need regular expressions here, and if you’re not familiar with them, I’d have to recommend against regexes.

    UPDATE:

    sections = []
    
    File.open("deneme") do |f|
      current = {:description => "", :text => "", :quality => "", :stats => ""}
      inDescription = false
      inQuality = false
    
      f.each_line do |line|
        if inDescription
          if line.strip == ""
            inDescription = false
          else
            current[:description] += line
          end
        elsif inQuality
          current[:quality] = line.strip
          inQuality = false
        elsif line.strip == "description"
          inDescription = true
        elsif line.strip == "quality"
          inQuality = true
        elsif line.match(/^text: /)
          current[:text] = line[6..-1].strip
        elsif line.match(/^stats /)
          current[:stats] = line[6..-1].strip
          sections.push(current)
          current = {:description => "", :text => "", :quality => "", :stats => ""}
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a text that I can easily parse. It consists of text
We can easily alert anything in java script. Is it possible to get this
In Bash I can easily do something like command1 && command2 || command3 which
Using scons I can easily set my include paths: env.Append( CPPPATH=['foo'] ) This passes
I am trying to parse an xml document in php which is somewhat tough
I have an xml which contains some keywords. The format of the xml this:
I am trying to parse the following xml. I can access the WeekNumber easily
I have an XML file containing data and I can easily parse it to
I can easily check IP addresses programmatically, but is there any way to set
I can easily calculate the age of a lead in minutes with a formula

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.