Class: Jekyll::Converters::Ingredient
- Defined in:
- lib/jekyll/converters/cooklang.rb
Instance Method Summary collapse
-
#initialize(quantity, unit, name) ⇒ Ingredient
constructor
A new instance of Ingredient.
- #to_html ⇒ Object
Methods inherited from ToHTML
Constructor Details
#initialize(quantity, unit, name) ⇒ Ingredient
Returns a new instance of Ingredient.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jekyll/converters/cooklang.rb', line 14 def initialize(quantity, unit, name) @name = name.to_s @unit = unit.to_s @quantity = if quantity.respond_to? :rationalize if quantity.rationalize(0.05).denominator == 1 quantity.to_s else quantity.rationalize(0.05).to_s end else quantity.to_s end end |
Instance Method Details
#to_html ⇒ Object
28 29 30 31 |
# File 'lib/jekyll/converters/cooklang.rb', line 28 def to_html return "<em>#{@quantity}</em> #{@name}" if @unit.empty? "<em>#{@quantity} #{@unit}</em> #{@name}" end |