README.md in aston-0.1.0 vs README.md in aston-0.2.0

- old
+ new

@@ -1,11 +1,9 @@ # Aston -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aston`. To experiment with that code, run `bin/console` for an interactive prompt. +The tiny library providing a tooling to deal with _ASTON_, which is like _JSON_, but isomorphic to _XML_. -TODO: Delete this and the text above, and describe your gem - ## Installation Add this line to your application's Gemfile: ```ruby @@ -20,21 +18,126 @@ $ gem install aston ## Usage -TODO: Write usage instructions here +```ruby +Aston.new(:root). + then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }. + then { |a| a.put_content([:bar, :baz], 'Hello, world!') } +#⇒ #<Aston:0x0000646926a11370 +# @attributes=#<Aston::Attributes:0x0000646926a112f8 @data={}>, +# @content= +# #<Aston::Content:0x0000646926a112d0 +# @data= +# [#<Aston:0x0000646926a110f0 +# @attributes=#<Aston::Attributes:0x0000646926a11078 @data={}>, +# @content= +# #<Aston::Content:0x0000646926a11050 +# @data= +# [#<Aston:0x0000646926a10f38 +# @attributes=#<Aston::Attributes:0x0000646926a10ec0 @data={"attr"=>"value"}>, +# @content=#<Aston::Content:0x0000646926a10e98 @data=["Hello, world!"]>, +# @name=:baz>]>, +# @name=:bar>]>, +# @name=:root> +``` -## Development +### `#to_s` -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +```ruby +puts Aston.new(:root). + then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }. + then { |a| a.put_content([:bar, :baz], "Hello, world!") }. + to_s +``` -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +```xml +<!-- Aston:1380:root --> +<root> + <!-- Aston:1400:bar --> + <bar> + <!-- Aston:1420:baz --> + <baz attr='value'> + Hello, world! + </baz> + </bar> +</root> +``` -## Contributing +### `#to_json` -Bug reports and pull requests are welcome on GitHub at https://github.com/am-kantox/aston. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/am-kantox/aston/blob/master/CODE_OF_CONDUCT.md). +```ruby +puts Aston.new(:root). + then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }. + then { |a| a.put_content([:bar, :baz], "Hello, world!") }. + to_json +#⇒ {"name":"root","attributes":{},"content":[ +# {"name":"bar","attributes":{},"content":[ +# {"name":"baz","attributes":{"attr":"value"},"content":["Hello, world!"]}]}]} +``` +### `Aston#parse_hash` + +```ruby +json = Aston.new(:root). + then { |a| a.put_attribute([:bar, :baz], 'attr', 'value') }. + then { |a| a.put_content([:bar, :baz], "Hello, world!") }. + to_json +Aston.parse_hash(JSON.parse(json)) +#⇒ #<Aston:0x0000643279caa890 +# @attributes=#<Aston::Attributes:0x0000643279caa868 @data={}>, +# @content= +# #<Aston::Content:0x0000643279caa840 +# @data= +# [#<Aston:0x0000643279caa930 +# @attributes=#<Aston::Attributes:0x0000643279caa908 @data={}>, +# @content= +# #<Aston::Content:0x0000643279caa8e0 +# @data= +# [#<Aston:0x0000643279caa9d0 +# @attributes=#<Aston::Attributes:0x0000643279caa9a8 @data={"attr"=>"value"}>, +# @content=#<Aston::Content:0x0000643279caa980 @data=["Hello, world!"]>, +# @name="baz">]>, +# @name="bar">]>, +# @name="root"> +``` + +### `#update_in` + +```ruby +a = Aston.new :aston, attributes: { foo: :bar } +a.put_attribute %i[bar baz], :ok, 42 +a.put_content %i[bar baz], 'Hello' +a.update_in %i[bar baz] do |content| + content << + Aston.new(:seq, attributes: { name: :seq1 }) << + Aston.new(:seq, attributes: { name: :seq2 }) << + Aston.new(:seq, attributes: { name: :seq3 }) +end + +#⇒ [#<Aston:0x0000643279c616e0 +# @attributes=#<Aston::Attributes:0x0000643279c61668 @data={:ok=>42}>, +# @content= +# #<Aston::Content:0x0000643279c61640 +# @data= +# ["Hello", +# #<Aston:0x0000643279c60d58 +# @attributes=#<Aston::Attributes:0x0000643279c60d08 @data={:name=>:seq1}>, +# @content=#<Aston::Content:0x0000643279c60ce0 @data=[]>, +# @name=:seq>, +# #<Aston:0x0000643279c60c68 +# @attributes=#<Aston::Attributes:0x0000643279c60c18 @data={:name=>:seq2}>, +# @content=#<Aston::Content:0x0000643279c60bc8 @data=[]>, +# @name=:seq>, +# #<Aston:0x0000643279c60b50 +# @attributes=#<Aston::Attributes:0x0000643279c60b00 @data={:name=>:seq3}>, +# @content=#<Aston::Content:0x0000643279c60ad8 @data=[]>, +# @name=:seq>]>, +# @name=:baz>] +``` + +`#update_in` returns an array of updated elements on the path given. Unlike `#update_in`. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).