Sha256: 9d13811196f1a4a80b76fd44e154efb645e9873f964ee717fb4468f473d2619c

Contents?: true

Size: 1.01 KB

Versions: 123

Compression:

Stored size: 1.01 KB

Contents

class Ingredient
  class << self
    def inherited(klass)
      ingredients << klass
    end

    attr_accessor :ingredients

    def ingredient(name, amount)
      name = name.to_s.gsub(/_/, '').capitalize
      if klass = ingredients.find { |n| n.to_s == name }
        klass.new(amount)
      else
        raise "unknown ingredient #{name}"
      end
    end
  end
  self.ingredients = []

  def initialize(amount = 1)
    @amount = amount
  end

  def name
    self.class.name.downcase
  end

  attr_reader :amount

  def to_s
    "#@amount #{name}"
  end
end

class Unit
  class << self
    def inherited(klass)
      units << klass
    end

    attr_accessor :units

    def unit(name, amount)
      name = name.to_s.gsub(/s$/, '').capitalize
      if klass = units.find { |n| n.to_s == name }
        klass.new(amount)
      end
    end
  end
  self.units = []

  def initialize(n = 1)
    @n = n
  end

  def name
    self.class.name.downcase
  end

  attr_reader :n

  def to_s
    "#@n #{name}#{@n > 1 ? 's' : ''}"
  end
end

Version data entries

123 entries across 109 versions & 8 rubygems

Version Path
tins-1.38.0 examples/recipe_common.rb
tins-1.37.1 examples/recipe_common.rb
tins-1.37.0 examples/recipe_common.rb
tins-1.36.1 examples/recipe_common.rb
tins-1.36.0 examples/recipe_common.rb
tins-1.35.0 examples/recipe_common.rb
tins-1.34.0 examples/recipe_common.rb
tins-1.33.0 examples/recipe_common.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/examples/recipe_common.rb
tins-1.32.1 examples/recipe_common.rb
tins-1.32.0 examples/recipe_common.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/examples/recipe_common.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/examples/recipe_common.rb
tins-1.31.1 examples/recipe_common.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/examples/recipe_common.rb
tins-1.31.0 examples/recipe_common.rb
tins-1.30.0 examples/recipe_common.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/examples/recipe_common.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/examples/recipe_common.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/examples/recipe_common.rb