Reading a YAML file

Hi,
I’m just starting to play around with YAML. I might use it instead of
XML. But, in IRB, I’m just trying the simplest, simplest thing. I’m just
trying to open the YAML file. And, I keep getting this “mapping” error.
I have no idea why.

irb(main):010:0> require ‘yaml’
=> false
irb(main):011:0> require ‘fileutils’
=> false
irb(main):012:0> Dir.chdir(“F:/workflows/grafix/images-BNA”)
=> 0
irb(main):013:0> file =
YAML.load_file(“F:/workflows/grafix/images-bna/suq115ab.yaml”)
Psych::SyntaxError: (F:/workflows/grafix/images-bna/suq115ab.yaml):
mapping values are not allowed in this context at line 3 column 11
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/psych.rb:370:in
parse' from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/psych.rb:370:inparse_stream’
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/psych.rb:318:in
parse' from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/psych.rb:245:inload’
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/psych.rb:464:in
block in load_file' from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/psych.rb:464:inopen’
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/psych.rb:464:in
load_file' from (irb):13 from C:/RailsInstaller/Ruby2.1.0/bin/irb:11:in

Thanks,
Peter

Without seeing the file it will be difficult to explain what is wrong.

Peter B. wrote in post #1168615:

Robert K. wrote in post #1168613:

Without seeing the file it will be difficult to explain what is wrong.

I attached the file. I’m not in the office right now, but, tomorrow
morning I’ll post it here.
Thanks.

This is it. Pretty simple. I based it totally on page 804 of the
“pickaxe” book.

imagename: suq115ab.pdf
workflow: bnagraphics
destination: “F:/workflows/grafix/bnagraphics”

Peter B. wrote in post #1168635:

Peter B. wrote in post #1168615:

Robert K. wrote in post #1168613:

Without seeing the file it will be difficult to explain what is wrong.

I attached the file. I’m not in the office right now, but, tomorrow
morning I’ll post it here.
Thanks.

This is it. Pretty simple. I based it totally on page 804 of the
“pickaxe” book.

imagename: suq115ab.pdf
workflow: bnagraphics
destination: “F:/workflows/grafix/bnagraphics”

This is a very good ref YAML link - http://yaml.org/YAML_for_ruby.html

Robert K. wrote in post #1168613:

Without seeing the file it will be difficult to explain what is wrong.

I attached the file. I’m not in the office right now, but, tomorrow
morning I’ll post it here.
Thanks.

Peter B. wrote in post #1168615:

Robert K. wrote in post #1168613:

Without seeing the file it will be difficult to explain what is wrong.

I attached the file. I’m not in the office right now, but, tomorrow
morning I’ll post it here.

Oh, sorry, I overlooked that. I think this mimics what you are trying
to do:

irb(main):009:0> puts({“foo”=>“bar”,1=>{2=>3}}.to_yaml)

foo: bar
1:
2: 3
=> nil

In other words: like “1” in my example you need a key for the nested
Hash:

irb(main):012:0> pp YAML.load_file(“suq115ab.yaml”)
{“imagename”=>“suq115ab.pdf”,
“data”=>
{“workflow”=>“bnagraphics”,
“destination”=>“F:/workflows/grafix/bnagraphics”}}
=> {“imagename”=>“suq115ab.pdf”, “data”=>{“workflow”=>“bnagraphics”,
“destination”=>“F:/workflows/grafix/bnagraphics”}}
irb(main):013:0> puts File.read(“suq115ab.yaml”)

imagename: suq115ab.pdf
data:
workflow: bnagraphics
destination: “F:/workflows/grafix/bnagraphics”

=> nil

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs