CHEMIO / chemistry_rails

A gem for validating chemical formula and calculating analysis
MIT License
5 stars 3 forks source link

Chemistry on Rails

===============

A gem for validating chemical formula and calculating elemental analysis

Installation

In Rails, add it to your Gemfile:

gem 'chemistry_rails'

Finally, restart the server to apply the changes.

Getting Started

Start off by creating a migration with a string field for the formula (if you don't have it already):

rails generate migration add_formula_to_chemicals
class AddFormulaToChemicals < ActiveRecord::Migration
  def change
    add_column :chemicals, :formula, :string
  end
end

Then run the migration to create the field:

rake db:migrate

Lastly, define the chemical_formula field in the model:

class Chemical < ActiveRecord::Base
  chemical_formula :formula
end

This will attach the ChemistryRails::Formula class to the field and you will be able to use it as described below. An ActiveRecord validation for chemical formula will be added.

the Formula class

To initialize a new object you need to pass the chemical formula as a string:

formula = ChemistryRails::Formula.new('C6H6')

The object has the following properties:

the ChemistryRails module

the module contains several useful methods:

constants:

Contributing

We welcome contributions to the repo. Please follow a Github friendly process:

  1. Fork the repository on Github
  2. Create a named feature branch
  3. Write your change
  4. Write tests for your change (if applicable)
  5. Run the tests, ensuring they all pass
  6. Submit a Pull Request using Github