Skip to content
/ massex Public

An elixir library for handling masses according to the whole value pattern. WIP.

License

Notifications You must be signed in to change notification settings

venndr/massex

Repository files navigation

Massex

Massex is a simple pattern for holding masses and interacting with them in a sensible manner. It follows the whole value pattern, and allows easy storage, retrieval and mathematics upon values of mass in disparate scales.

iex> one = Massex.new(10, :gram)
...> two = Massex.new(10, :ounce)
...> Massex.add(one, two)

All the documentation is on HexDocs

Supporting Libraries

Massex ships with Jason support which will automatically be loaded if your project is using Jason for JSON handling. Additionally, it also supports Absinthe and Ecto.

Absinthe

To activate the Absinthe support, just import the types in your schema:

import_types Massex.Absinthe.Type

You can then use Massex objects in your Schemas

object :lorry do
  field :mass, :mass
end

Or in your mutations

payload field :set_lorry_mass do
  input do
    field :id, non_null(:id)
    field :mass, non_null(:mass_input)
  end
end

Ecto

You can transparently store Massex structs in your schemas by adding the mass field as a map/json/jsonb type in your schema.

schema "lorries" do
  field :mass, Massex.Ecto.Type
end

Installation

If available in Hex, the package can be installed by adding massex to your list of dependencies in mix.exs:

def deps do
  [
    {:massex, "~> 0.1.0"}
  ]
end

Licence

ISC License

Copyright (c) 2024 Music Glue

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

A copy of the licence text is also included in the file LICENSE.


Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/massex.

About

An elixir library for handling masses according to the whole value pattern. WIP.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages