Module: RestaurantsHelper

Included in:
RestaurantWidgetSerializer
Defined in:
app/helpers/restaurants_helper.rb

Overview

typed: true encoding: utf-8 frozen_string_literal: true

Instance Method Summary collapse

Instance Method Details

#join_restaurant_tags(restaurant) ⇒ Object

noinspection RubyResolve



7
8
9
# File 'app/helpers/restaurants_helper.rb', line 7

def join_restaurant_tags(restaurant)
  restaurant.restaurant_tags.map(&:title).join(', ')
end


54
55
56
57
# File 'app/helpers/restaurants_helper.rb', line 54

def link_to_admin_restaurant_package_path_by_dynamic_id(restaurant_id, dynamic_id, label, additional_params = {})
  query_params = { id: dynamic_id }.merge(additional_params)
  link_to label, admin_restaurant_restaurant_packages_path(restaurant_id, query_params), class: 'link'
end

#party_size_html(restaurant) ⇒ Object



19
20
21
22
23
# File 'app/helpers/restaurants_helper.rb', line 19

def party_size_html(restaurant)
  restaurant.party_size_range.map do |seat|
    "<option value='#{seat}' #{'selected' if seat == 2}>#{seat}</option>"
  end
end

#price_to_dollars_symb(num) ⇒ Object



11
12
13
14
15
16
17
# File 'app/helpers/restaurants_helper.rb', line 11

def price_to_dollars_symb(num)
  price = ''
  num.times do
    price += '$'
  end
  price
end

#subunits_to_units(amount_subunit, currency_code) ⇒ BigDecimal

Convert price from cents (subunit) to dollars (unit) based on currency

Examples:

subunits_to_units(1000, 'THB') # => 10
subunits_to_units(2500, 'THB') # => 25
subunits_to_units(450, 'SGD') # => 4.5

Parameters:

  • amount_subunit (Integer)

    The price in cents (subunit).

  • currency_code (String)

    The currency code (e.g., 'THB', 'USD', 'SGD').

Returns:

  • (BigDecimal)

    The price in dollars (unit).



34
35
36
37
38
# File 'app/helpers/restaurants_helper.rb', line 34

def subunits_to_units(amount_subunit, currency_code)
  return 0 if amount_subunit.blank? || currency_code.blank?

  Money.new(amount_subunit, currency_code).amount
end

#units_to_subunits(amount_unit, currency_code) ⇒ Integer

Convert price from dollars (unit) to cents (subunit) based on currency

Examples:

units_to_subunits(10, 'THB') # => 1000
units_to_subunits(25, 'THB') # => 2500
units_to_subunits(450, 'SGD') # => 45000

Parameters:

  • amount_unit (BigDecimal)

    The price in dollars (unit).

  • currency_code (String)

    The currency code (e.g., 'THB', 'USD', 'SGD').

Returns:

  • (Integer)

    The price in cents (subunit).



48
49
50
51
52
# File 'app/helpers/restaurants_helper.rb', line 48

def units_to_subunits(amount_unit, currency_code)
  return 0 if amount_unit.blank? || currency_code.blank?

  Money.from_amount(amount_unit, currency_code).cents
end