<commit_before>Representative
==============

"Representative" makes it easier to create XML representations of your Ruby objects.
It works best when you want the XML to roughly follow the object structure, 
but still have complete control of the result.

Example
-------

Given a Ruby data-structure:

    books = [
      OpenStruct.new(
        :title => "Sailing for old dogs", 
        :authors => ["<NAME>"],
        :published => OpenStruct.new(
          :by => "Credulous Print",
          :year => 1994
        )
      ),
      OpenStruct.new(
        :title => "On the horizon", 
        :authors => ["<NAME>", "<NAME>"],
        :published => OpenStruct.new(
          :by => "McGraw-Hill",
          :year => 2005
        )
      ),
      OpenStruct.new(
        :title => "The Little Blue Book of VHS Programming",
        :authors => ["<NAME>"],
        :rating => "****"
      )
    ]

Representative::Xml can be used to generate XML, in a declarative style:

    xml = Builder::XmlMarkup.new(:indent => 2)
    representative = Representative::Xml.new(xml)

    representative.list_of!(:books, books) do |_book|
      _book.title
      _book.list_of!(:authors)
      _book.published do |_published|
        _published.by
        _published.year
      end
    end

    puts xml.target!

The resulting XML looks like this:

    <books type="array">
      <book>
        <title>Sailing for old dogs</title>
        <authors type="array">
          <author><NAME></author>
        </authors>
        <published>
          <by>Credulous Print</by>
          <year>1994</year>
        </published>
      </book>
      <book>
        <title>On the horizon</title>
        <authors type="array">
          <author><NAME></author>
          <author><NAME></author>
        </authors>
        <published>
          <by>McGraw-Hill</by>
          <year>2005</year>
        </published>
      </book>
      <book>
        <title>The Little Blue Book of VHS Programming</title>
        <authors type="array">
          <author><NAME></author>
        </authors>
        <published/>
      </book>
    </books>

Notice that:

- Representative generates elements for each object-attribute you name (and not the ones you don't).
- The structure of the XML mirrors the structure described by the nested Ruby blocks.
- Using `list_of!` for a collection attribute generates an "array" element, which plays nicely
  with most Ruby XML-to-hash converters.
- Where a named object-attribute is nil, you get an empty element.

Installation
------------

Representative is packaged as a Gem, hosting on [gemcutter].  Install with:

    sudo gem install representative --source http://gemcutter.org

Copyright
---------

Copyright (c) 2009 <NAME>. See LICENSE for details.

[gemcutter]: http://gemcutter.org/<commit_msg>Fix install instructions.<commit_after>Representative
==============

"Representative" makes it easier to create XML representations of your Ruby objects.
It works best when you want the XML to roughly follow the object structure, 
but still have complete control of the result.

Example
-------

Given a Ruby data-structure:

    books = [
      OpenStruct.new(
        :title => "Sailing for old dogs", 
        :authors => ["<NAME>"],
        :published => OpenStruct.new(
          :by => "Credulous Print",
          :year => 1994
        )
      ),
      OpenStruct.new(
        :title => "On the horizon", 
        :authors => ["<NAME>", "<NAME>"],
        :published => OpenStruct.new(
          :by => "McGraw-Hill",
          :year => 2005
        )
      ),
      OpenStruct.new(
        :title => "The Little Blue Book of VHS Programming",
        :authors => ["<NAME>"],
        :rating => "****"
      )
    ]

Representative::Xml can be used to generate XML, in a declarative style:

    xml = Builder::XmlMarkup.new(:indent => 2)
    representative = Representative::Xml.new(xml)

    representative.list_of!(:books, books) do |_book|
      _book.title
      _book.list_of!(:authors)
      _book.published do |_published|
        _published.by
        _published.year
      end
    end

    puts xml.target!

The resulting XML looks like this:

    <books type="array">
      <book>
        <title>Sailing for old dogs</title>
        <authors type="array">
          <author><NAME></author>
        </authors>
        <published>
          <by>Credulous Print</by>
          <year>1994</year>
        </published>
      </book>
      <book>
        <title>On the horizon</title>
        <authors type="array">
          <author><NAME></author>
          <author><NAME></author>
        </authors>
        <published>
          <by>McGraw-Hill</by>
          <year>2005</year>
        </published>
      </book>
      <book>
        <title>The Little Blue Book of VHS Programming</title>
        <authors type="array">
          <author><NAME></author>
        </authors>
        <published/>
      </book>
    </books>

Notice that:

- Representative generates elements for each object-attribute you name (and not the ones you don't).
- The structure of the XML mirrors the structure described by the nested Ruby blocks.
- Using `list_of!` for a collection attribute generates an "array" element, which plays nicely
  with most Ruby XML-to-hash converters.
- Where a named object-attribute is nil, you get an empty element.

Installation
------------

Representative is packaged as a Gem, hosted on [gemcutter](http://gemcutter.org/gems/representative).  Install with:

    sudo gem install representative --source http://gemcutter.org

Copyright
---------

Copyright (c) 2009 <NAME>. See LICENSE for details.
{'fraction_non_alphanumeric': 0.13220940550133098, 'fraction_numerical': 0.007453416149068323, 'mean_word_length': 2.2242562929061784, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 131, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3046784', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1554, 'n_words': 505}