Skip to content

Instantly share code, notes, and snippets.

@pronoiac
Last active January 5, 2022 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pronoiac/26df03298422841e9d143676f866aa8e to your computer and use it in GitHub Desktop.
Save pronoiac/26df03298422841e9d143676f866aa8e to your computer and use it in GitHub Desktop.
shuffling yaml in ruby
APTITUDES:
- Fighting
- Presence
- Aircraft
- Occultism
- Technology
- Business
- Performance
- Vehicles
POWERS:
- Absorption
- Insubstantiality
- Summoning
- Life Support
- Super Leap
- Burrowing
- Mental Blast
- Super Running
- Communication
- Mental Paralysis
  • Category: APTITUDES

    • Performance
    • Fighting
    • Occultism
  • Category: POWERS

    • Mental Paralysis
    • Insubstantiality
    • Communication
#!/usr/bin/env ruby
require 'yaml'
require 'pp' # Pretty printer
# require 'byebug' # for debugging
# Open yaml File
# superstuff = YAML.load_file('/home/username/data/sample.yaml')
superstuff = YAML.load_file('categories.yml') # if you're running it from the same directory
# byebug
# puts "pause"
# Iterate through what's there, and hopefully randomly sample some data.
superstuff.each do |category|
# byebug
category_name = category.first
category_options = category.last
draw_3 = category_options.sample(3)
puts "- Category: #{category_name}"
draw_3.each do |item|
puts " - #{item}"
end
puts # blank line in between categories
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment