This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
doc = Psych.parse(str) | |
# "A Psych::Nodes::Stream node must have 1 or more Psych::Nodes::Document nodes as children. | |
# Psych::Nodes::Document nodes must have one and only one child." | |
nodes = doc.children.first | |
nodes.each do |n| | |
puts n.value if n.respond_to? 'value' | |
end | |
# Output of the above: | |
# original_work | |
# title | |
# كتاب الفروسية والبيطرة | |
# alternative_title | |
# الفروسية وشيات الخيل | |
pp nodes # Output: see nodes.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- original_work: | |
- title: ﻚﺗﺎﺑ ﺎﻠﻓﺭﻮﺴﻳﺓ ﻭﺎﻠﺒﻴﻃﺭﺓ | |
- alternative_title: ﺎﻠﻓﺭﻮﺴﻳﺓ ﻮﺸﻳﺎﺗ ﺎﻠﺨﻴﻟ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#<Psych::Nodes::Sequence:0x00000000022c51f8 | |
@anchor=nil, | |
@children= | |
[#<Psych::Nodes::Mapping:0x00000000022c5158 | |
@anchor=nil, | |
@children= | |
[#<Psych::Nodes::Scalar:0x00000000022c4fa0 | |
@anchor=nil, | |
@end_column=15, | |
@end_line=0, | |
@plain=true, | |
@quoted=false, | |
@start_column=2, | |
@start_line=0, | |
@style=1, | |
@tag=nil, | |
@value="original_work">, | |
#<Psych::Nodes::Sequence:0x00000000022c4f78 | |
@anchor=nil, | |
@children= | |
[#<Psych::Nodes::Mapping:0x00000000022c4e60 | |
@anchor=nil, | |
@children= | |
[#<Psych::Nodes::Scalar:0x00000000022c4dc0 | |
@anchor=nil, | |
@end_column=9, | |
@end_line=1, | |
@plain=true, | |
@quoted=false, | |
@start_column=4, | |
@start_line=1, | |
@style=1, | |
@tag=nil, | |
@value="title">, | |
#<Psych::Nodes::Scalar:0x00000000022c4d20 | |
@anchor=nil, | |
@end_column=33, | |
@end_line=1, | |
@plain=true, | |
@quoted=false, | |
@start_column=11, | |
@start_line=1, | |
@style=1, | |
@tag=nil, | |
@value="كتاب الفروسية والبيطرة">], | |
@end_column=2, | |
@end_line=2, | |
@implicit=true, | |
@start_column=4, | |
@start_line=1, | |
@style=1, | |
@tag=nil>, | |
#<Psych::Nodes::Mapping:0x00000000022c4c80 | |
@anchor=nil, | |
@children= | |
[#<Psych::Nodes::Scalar:0x00000000022c4bb8 | |
@anchor=nil, | |
@end_column=21, | |
@end_line=2, | |
@plain=true, | |
@quoted=false, | |
@start_column=4, | |
@start_line=2, | |
@style=1, | |
@tag=nil, | |
@value="alternative_title">, | |
#<Psych::Nodes::Scalar:0x00000000022c4a78 | |
@anchor=nil, | |
@end_column=43, | |
@end_line=2, | |
@plain=true, | |
@quoted=false, | |
@start_column=23, | |
@start_line=2, | |
@style=1, | |
@tag=nil, | |
@value="الفروسية وشيات الخيل">], | |
@end_column=0, | |
@end_line=3, | |
@implicit=true, | |
@start_column=4, | |
@start_line=2, | |
@style=1, | |
@tag=nil>], | |
@end_column=0, | |
@end_line=3, | |
@implicit=true, | |
@start_column=2, | |
@start_line=1, | |
@style=1, | |
@tag=nil>], | |
@end_column=0, | |
@end_line=3, | |
@implicit=true, | |
@start_column=2, | |
@start_line=0, | |
@style=1, | |
@tag=nil>], | |
@end_column=0, | |
@end_line=3, | |
@implicit=true, | |
@start_column=0, | |
@start_line=0, | |
@style=1, | |
@tag=nil> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment