[ANN] flexparser 1.0.3 - XML parser DSL with focus on data-normalization


(Paul Martensen) #1

Hi!

Imagine this: You have a bunch of XML documents with similar information, but wildly different structure.
For example you want to check inventories of differing stores and one has its prices listed as a tag, the other as a property.
And also one calls its items "items" and the other calls them "products". Awful!
Now you could write 2 parser for each one and use the correct one for each type of document. But that sounds annoying.

flexparser lets you write one parser for all of your documents:

class StoreParser
  include Flexparser

  property 'store' do
    property %w[item product], collection: true do
      property 'name'
      property %w[price @price], transformation: :to_f # Parse either a tag or an attribute.

    end
  end
end

parsed = StoreParser.parse xml # You can now pass any of the two xml documents

parsed.store.item.first.price #=> Float<10.5>

If you have a similar problem, come check it out!

Github: https://github.com/lokalportal/flexparser
Rubygems: https://rubygems.org/gems/flexparser

Happy Coding!

Paul