class MenuMarkup::ParsedPrice

Constants

BOP
COMMA_DECIMAL
CURRENCY
DASH
DASH_COMMA_DECIMAL
DASH_DOT_DECIMAL
DOT_DECIMAL
EOP
FULL_COMMA_DECIMAL
FULL_DOT_DECIMAL
INTEGER
LITERAL
POST_CURRENCY_COMMA
POST_CURRENCY_DASH_COMMA
POST_CURRENCY_DASH_DOT
POST_CURRENCY_DOT
POST_CURRENCY_FULL_COMMA
POST_CURRENCY_FULL_DOT
POST_CURRENCY_INTEGER
PRE_CURRENCY_COMMA
PRE_CURRENCY_DASH_COMMA
PRE_CURRENCY_DASH_DOT
PRE_CURRENCY_DOT
PRE_CURRENCY_FULL_COMMA
PRE_CURRENCY_FULL_DOT
PRE_CURRENCY_INTEGER
PRICES

Attributes

money[RW]
title[RW]
unit[RW]

Public Class Methods

find_match(text, options = {}) click to toggle source
# File lib/menu_markup/parsed_price.rb, line 46
def self.find_match(text, options = {})
  options.reverse_merge!(eop: EOP, bop: BOP)
  PRICES.each do |regex|
    return $~ if text.scan(/#{options[:bop]}#{regex}#{options[:eop]}/ui).present?
  end
  nil
end
new(money, title = nil, unit = nil) click to toggle source
# File lib/menu_markup/parsed_price.rb, line 63
def initialize(money, title = nil, unit = nil)
  # In case this is literal price, we want to set it as title of price and not money
  if money =~ LITERAL
    title = "#{title}#{money}#{unit}"
    money = nil
  end

  @money, @title, @unit = money.presence, title.presence, unit.presence
  # Replace .- with .00
  @money.gsub!(/([\.,])#{DASH}/, "\\100") if @money
end
parse_line(line) click to toggle source
# File lib/menu_markup/parsed_price.rb, line 54
def self.parse_line(line)
  match = find_match(line)
  if match
    new(match.to_s, match.pre_match, match.post_match)
  else
    new(nil, line)
  end
end