How to read an external YAML file on the internet and output to XML



I need to be able to make a Ruby application (no Rails, if possible) that opens an external YAML file that has over 104K lines of code in it, reads from it and filters out the following three things:



!ruby/object:EvtEvent
!ruby/object:NwsPost
!ruby/object:Asset


and then outputs these things to an XML file that would have to be built by the Ruby program.




  1. I am unclear how to start with setting this up, as I am only a junior-level developer with one year's experience.




  2. Although I found something on Stack Overflow that shows this snippet of a code example on using Nokogiri, I don't know exactly where to put this code which I would have to modify for my situation:



    require 'yaml'
    require 'nokogiri'

    yaml = "getOrderDetails:
    Id: '114'
    Name: 'XYZ'"
    doc = YAML.load yaml

    output = Nokogiri::XML::Builder.new do |xml|
    xml.product{
    xml.id doc["getOrderDetails"]["Id"]
    xml.name doc["getOrderDetails"]["Name"]
    }
    end
    puts output.to_xml
    #=> <?xml version="1.0"?>
    #=> <product>
    #=> <id>114</id>
    #=> <name>XYZ</name>
    #=> </product>



  3. How would I code the init.rb file to launch a Ruby program that would open the YAML file in question, read from it, and then output it to XML?




  4. What other Ruby files would I need to put in my lib folder for such a Ruby program to handle this task?




No comments:

Post a Comment