<commit_before># CollectionJson::Serializer

[![Build Status](https://travis-ci.org/carlesjove/collection_json_serializer.svg?branch=master)](https://travis-ci.org/carlesjove/collection_json_serializer)

| :warning: This is _not finished_ yet, so use it at your own risk. Until
version 1.X breaking changes might happen |
--------------------------------------------------------------------

CollectionJson::Serializer serializes Ruby objects to Collection+JSON, the hypermedia type by <NAME>.

Please note that CollectionJson::Serializer _only serializes data_. You still need to set the proper Headers or media-types in your app.

If you're working on a Rails app, you might want to use [Collection+JSON
Rails](https://github.com/carlesjove/collection_json_rails) instead.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'collection_json_serializer'
```

And then execute:

    $ bundle


## Usage

As this gem user, you will be mainly writing/generating and mantaining serializers for your models. A serializer goes like:

```ruby
class UserSerializer < CollectionJson::Serializer
  href "http://example.com/users",

  template :name
  template email: { prompt: "My email" }

  link dashboard: { href: "http://example.com/my-dashboard" }

  query search: {
    href: "http://example.com/search",
    name: false # Don't automatically include the name attribute
  }
  query pagination: {
    rel: "page",
    href: "http://example.com/page",
    prompt: "Select a page number",
    data: [
      { name: "page" }
    ]
  }

  items do
    attribute :id
    attribute name: { prompt: "Your full name" }}
    attribute :email
    attribute date_created: { prompt: "Member since"}

    href "http://example.com/users/{id}"

    link avatar: { href: "http://assets.example.com/avatar.jpg", render: "image" }
  end
end
```

Then, you pass your objects to the serializer:

```ruby
@user = User.new(name: "<NAME>", email: "<EMAIL>")

# Pass it to the serializer
user_serializer = UserSerializer.new(@user)<commit_msg>fix stuff in README<commit_after># CollectionJson::Serializer

[![Build Status](https://travis-ci.org/carlesjove/collection_json_serializer.svg?branch=master)](https://travis-ci.org/carlesjove/collection_json_serializer)

| :warning: This is _not finished_ yet, so use it at your own risk. |
--------------------------------------------------------------------
| :warning: Until version 1.X breaking changes might happen |
-------------------------------------------------------------

CollectionJson::Serializer serializes Ruby objects to Collection+JSON, the hypermedia type by Mike Amudsen.

Please note that CollectionJson::Serializer _only serializes data_. You still need to set the proper Headers or media-types in your app.

If you're working on a Rails app, you might want to use [Collection+JSON
Rails](https://github.com/carlesjove/collection_json_rails) instead.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'collection_json_serializer'
```

And then execute:

    $ bundle


## Usage

As this gem user, you will be mainly writing/generating and mantaining serializers for your models. A serializer goes like:

```ruby
class UserSerializer < CollectionJson::Serializer
  href "http://example.com/users",

  template :name
  template email: { prompt: "My email" }

  link dashboard: { href: "http://example.com/my-dashboard" }

  query search: {
    href: "http://example.com/search",
    name: false # Don't automatically include the name attribute
  }
  query pagination: {
    rel: "page",
    href: "http://example.com/page",
    prompt: "Select a page number",
    data: [
      { name: "page" }
    ]
  }

  items do
    attribute :id
    attribute name: { prompt: "Your full name" }}
    attribute :email

    href "http://example.com/users/{id}"

    link avatar: { href: "http://assets.example.com/avatar.jpg", render: "image" }
  end
end
```

Then, you pass your objects to the serializer:

```ruby
@user = User.new(name: "<NAME>", email: "<EMAIL>")

# Pass it to the serializer
user_serializer = UserSerializer.new(@user)
{'fraction_non_alphanumeric': 0.16018473505104522, 'fraction_numerical': 0.0004861448711716091, 'mean_word_length': 3.2422680412371134, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3150698', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1170, 'n_words': 391}