README.md in acb-0.1.0 vs README.md in acb-0.1.1

- old
+ new

@@ -1,33 +1,68 @@ # Acb -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/acb`. To experiment with that code, run `bin/console` for an interactive prompt. +Acb is a gem for formatting and outputting csv data from ActiveRecord data -TODO: Delete this and the text above, and describe your gem - ## Installation Install the gem and add to the application's Gemfile by executing: $ bundle add acb -If bundler is not being used to manage dependencies, install the gem by executing: - $ gem install acb - ## Usage -TODO: Write usage instructions here -## Development +```ruby +ActiveRecord::Schema.define do + create_table :users, force: true do |t| + t.string :name + end -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. + create_table :posts, force: true do |t| + t.integer :user_id + t.timestamps + end -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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + create_table :comments, force: true do |t| + t.integer :post_id + t.string :content + end +end -## Contributing +class User < ActiveRecord::Base + has_many :posts +end -Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/acb. 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/[USERNAME]/acb/blob/main/CODE_OF_CONDUCT.md). +class Post < ActiveRecord::Base + belongs_to :user + has_many :comments +end +class Comment < ActiveRecord::Base + belongs_to :post +end + +class PostCsvBuilder + include Acb + + add_column name: 'id' + add_column name: 'User Name', index: 'user.name' + add_column name: 'created_at', format: '%Y-%m-%d' + add_column name: 'Comment Amount', index: 'comments.size' + add_column name: 'First Comment', index: ->(post) { post.comments.first&.content } + + def initialize(user_id) + @data = Post.where(user_id: user_id) + end + + def relations + [:user, :comments] + end +end + +PostCsvBuilder.new(user_id).content_string +``` + ## Code of Conduct -Everyone interacting in the Acb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/acb/blob/main/CODE_OF_CONDUCT.md). +Everyone interacting in the Acb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/kakubin/acb/blob/main/CODE_OF_CONDUCT.md).