Class: EhbrsRubyUtils::CookingBook::Recipe::Measure
- Inherits:
-
Object
- Object
- EhbrsRubyUtils::CookingBook::Recipe::Measure
- Defined in:
- lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb
Constant Summary collapse
- FLOAT_PATTERN =
/\d+(?:\.\d+)?/.freeze
- FRACTION_PATTERN =
%r{(#{FLOAT_PATTERN})(?:\s*/\s*(#{FLOAT_PATTERN}))?}.freeze
- QUANTITY_UNIT_PATTERN =
/\A#{FRACTION_PATTERN}(?:\s*(\S+))?\z/.freeze
- VARIABLE_PATTERN =
/\A~\z/.freeze
- VARIABLE_TEXT =
'a gosto'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.build(value) ⇒ Object
18 19 20 21 |
# File 'lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb', line 18 def build(value) value = value.to_s.strip build_from_variable(value) || build_from_pattern(value) || build_unknown(value) end |
Instance Method Details
#quantity_to_s ⇒ Object
50 51 52 |
# File 'lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb', line 50 def quantity_to_s numerator.to_s + (denominator.if_present('') { |v| "/ #{v}" }) end |
#to_s ⇒ Object
44 45 46 47 48 |
# File 'lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb', line 44 def to_s return VARIABLE_TEXT if variable? "#{quantity_to_s} #{unit}" end |
#variable? ⇒ Boolean
54 55 56 |
# File 'lib/ehbrs_ruby_utils/cooking_book/recipe/measure.rb', line 54 def variable? numerator.blank? end |