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 7039797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:50:29+00:00 2026-05-28T01:50:29+00:00

I have the following data in a yaml file – — – :Subject_list Subject

  • 0

I have the following data in a yaml file –

---
- :Subject_list 
    Subject 1: 
     :Act 1: A
     :Act 2: B
    Subject 2: 
     :Skill 1: 
       :Act 1: B
       :Act 2: B  
     :Skill 2:
       :Act 1: B

I need to read data from this file and and generate an output which is given below –
For subject 1 it will be like this as it has no skill level. Meaning the first element of the array is null.

  ["","Act 1", "A"], ["","Act 2", "B"]

For the second subject it will be like this –

  ["Skill 1","Act 1", "B"], ["","Act 2" "B"],["Skill 2","Act 1", "B"]

I am using these values to generate a prawn pdf table. Any help is greatly appreciated.

I tried doing this –

data=YAML::load(File.read("file.yaml"));
subject = data[:Subject_list]
sub_list =["Subject 1", "Subject 2"]

  sub_list.each do |sub|
      sub_data = []
      sub_data = subject["#{sub}"]
         # I convert the list symbol to an array, so i can loop through the sub     activities. 
         #I need some direction here as how to check whether the symbol will be a skill or activity
      end

Cheers!!

  • 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-28T01:50:30+00:00Added an answer on May 28, 2026 at 1:50 am

    First off, your yaml file is not correct YAML, you cannot have keys like that, if you have space or weirdness in them you need to quote them, and what’s up with the : at the beginning?

    "Subject_list":
      "Subject 1": 
        "Act 1": A
        "Act 2": B
      "Subject 2": 
        "Skill 1": 
          "Act 1": B
          "Act 2": B  
        "Skill 2":
          "Act 1": B
    

    Then you need to load the file properly. You call the method load_file on the YAML module. No :: for method access in ruby afaik.

    require 'yaml'
    data = YAML.load_file "file.yaml"
    subject = data["Subject_list"]
    
    require 'pp'
    subject.each do |s|
      item = s.last
      if item.keys.first =~ /Skill/
        pp item.keys.inject([]) { |memo,x| item[x].map { |i| memo << i.flatten.unshift(x) } ; memo}
      else
        pp item.map { |k,v| ["", k, v] }
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following data in text file 375020222511963 284970411563422 290245594366931 I need to retrieve
I have following CSV data: 10,11,12.34 I can parse this using CSV from the
I have a yaml file that looks like this: # The following key opens
I have the following data that I parsed from an xml file and now
I have following data in a file called binFile 78 1 79 4 80
I have the following data in mysql: file-id 32-534 32-536 32-537 32-584 32-594 46-865
I have the following data in mysql database which is an iframe from u-tube:-
I have a column in a table defined as following in my yaml file:
I have the following data - it is a dump from a normalized database,
I am trying to load data from a YAML file where some fields contain

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.