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


i need able make ruby application (no rails, if possible) opens external yaml file has on 104k lines of code in it, reads , filters out following 3 things:

!ruby/object:evtevent !ruby/object:nwspost !ruby/object:asset 

and outputs these things xml file have built ruby program.

  1. i unclear how start setting up, junior-level developer 1 year's experience.

  2. although found on stack overflow shows snippet of code example on using nokogiri, don't know put code have modify situation:

    require 'yaml' require 'nokogiri'  yaml = "getorderdetails: id: '114' name: 'xyz'" doc = yaml.load yaml  output = nokogiri::xml::builder.new |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 code init.rb file launch ruby program open yaml file in question, read it, , output xml?

  4. what other ruby files need put in lib folder such ruby program handle task?

  1. the code can go wherever it's convenient. ruby has no real expectation of file locations; run them. development team has guidelines, need talk them.

  2. "init.rb" non-descriptive name file. try use more indicative of purpose of script.

  3. reading remove file purpose easy openuri:

    foo = open('http://domain.com/path/to/file.yaml').read 

    will return contents of file , store them in variable foo.

  4. the contents of yaml can parsed using:

    yaml = yaml.load(foo) 

    at point haml contain array or hash, can accessed normal.

    what's more interesting that, once openuri loaded, patch open method, should make possible like:

    require 'open-uri' yaml = yaml.load_file('http://domain.com/path/to/file.yaml') 

    yaml has open file load disk, load_file does, , after openuri magic yaml class should have inherited magic. haven't tested should work.

  5. nokogiri's builder interface way go.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -