README.md in json-streamer-1.1.2 vs README.md in json-streamer-1.2.0
- old
+ new
@@ -45,22 +45,29 @@
## Usage
```ruby
require 'json/streamer'
+```
+### v1.1.3 API
+
+Check the unit tests for more examples ([spec/streamer_spec.rb](spec/json/streamer/json_streamer_spec.rb)).
+
+#### Passing IO upfront
+
+```ruby
file_stream = File.open('data.json', 'r')
+chunk_size = 500 # defaults to 1000
-# Get a JsonStreamer object that will parse file_stream by chunks of 500
-# Default chunk size in 1000
-streamer = Json::Streamer::JsonStreamer.new(file_stream, 500)
+streamer = Json::Streamer.parser(file_io: file_stream, chunk_size: chunk_size)
```
#### Get objects based on nesting level
```ruby
-# Level zero will give you the full JSON, first level will give you data within full JSON object, etc.
+# Level zero yields the full JSON, first level yields data within the JSON 1-by-1, etc.
streamer.get(nesting_level:1) do |object|
p object
end
```
@@ -107,11 +114,11 @@
"value2"
"value3"
{"desired_key" : "value3"}
```
-#### Skip values if you'd only like to get objects and arrays
+#### Skip values
```ruby
streamer.get(nesting_level:1, yield_values:false) do |object|
p object
end
@@ -128,49 +135,64 @@
Output:
```json
{}
```
-#### EventMachine-style input (since 1.1.0)
+#### Passing IO later (EventMachine-style)
```ruby
# Get a JsonStreamer object that provides access to the parser
# but does not start processing immediately
-streamer = Json::Streamer::JsonStreamer.new
+streamer = Json::Streamer.parser
streamer.get(nesting_level:1) do |object|
p object
end
```
Then later in your EventMachine handler:
```ruby
def receive_data(data)
- streamer.parser << data
+ streamer << data
end
```
-Check the unit tests for more examples ([spec/streamer_spec.rb](spec/streamer_spec.rb)).
+### Legacy API (pre-v1.1.3)
+This functionality is deprecated but kept for compatibility reasons.
+
+```ruby
+# Same as Json::Streamer.parser
+streamer = Json::Streamer::JsonStreamer.new
+```
+
+```ruby
+# Same as streamer << data
+streamer.parser << data
+```
+
## Feedback
Any feedback is much appreciated.
I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.
Please let me know if you make use of this project so that I can prioritize further efforts.
-## Development
+## Conventions
-After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
+This gem is developed using the following conventions:
+- [Bundler's guide for developing a gem](http://bundler.io/v1.14/guides/creating_gem.html)
+- [Better Specs](http://www.betterspecs.org/)
+- [Semantic versioning](http://semver.org/)
+- [RubyGems' guide on gem naming](http://guides.rubygems.org/name-your-gem/)
+- [RFC memo about key words used to Indicate Requirement Levels](https://tools.ietf.org/html/rfc2119)
+- [Bundler improvements](https://github.com/thisismydesign/bundler-improvements)
-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).
-
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/json-streamer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
-
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).