Created
August 3, 2017 08:52
-
-
Save kelevro/61b21c7203162ac66a6e1834a95c002f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # == Schema Information | |
| # | |
| # Table name: ingridients | |
| # | |
| # id :integer not null, primary key | |
| # measurement :integer default(0), not null | |
| # measurement_type :integer default(0), not null | |
| # recipe_id :integer | |
| # created_at :datetime not null | |
| # updated_at :datetime not null | |
| # name :string | |
| # | |
| # Indexes | |
| # | |
| # index_ingridients_on_recipe_id (recipe_id) | |
| # | |
| # Foreign Keys | |
| # | |
| # fk_rails_6d8c955de5 (recipe_id => recipes.id) | |
| # | |
| class Ingridient < ActiveRecord::Base | |
| belongs_to :recipe | |
| validates :measurement, presence: true | |
| validates :measurement_type, presence: true | |
| MEASUREMENTS = { | |
| '-' => -1, | |
| '1/16' => 0, | |
| '1/8' => 1, | |
| '1/4' => 2, | |
| '1/3' => 3, | |
| '1/2' => 4, | |
| '2/3' => 5, | |
| '3/4' => 6, | |
| '1' => 7, | |
| '2' => 8, | |
| '4' => 9, | |
| '8' => 10, | |
| '16' => 11, | |
| '3' => 12, | |
| } | |
| MEASUREMENT_TYPES = [ | |
| 'oz', | |
| 'cup', | |
| 'tsp', | |
| 'tbsp', | |
| 'fl oz', | |
| 'pt', | |
| 'qt', | |
| 'gal', | |
| 'ml', | |
| 'in', | |
| 'lbs' | |
| ] | |
| enum measurement: MEASUREMENTS | |
| enum measurement_type: MEASUREMENT_TYPES | |
| def measure | |
| measurement + ' ' + measurement_type | |
| end | |
| def to_label | |
| "#{name} (#{measure})" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment