Module: CashRegister::Promotions

Defined in:
lib/cash_register/promotions.rb

Overview

促销列表

Class Method Summary collapse

Class Method Details

.init_promotions(promotions_json_path) ⇒ Object



6
7
8
9
10
11
# File 'lib/cash_register/promotions.rb', line 6

def init_promotions(promotions_json_path)
  @promotions ||= {}
  (JSON.parse(File.read(promotions_json_path)) rescue []).map do  |promotion|
    @promotions[promotion['type']] = promotion['deals']
  end
end

.is_discount?(code = '') ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/cash_register/promotions.rb', line 17

def is_discount?(code = '')
  (@promotions['DISCOUNT'] rescue []).include?(code)
end

.is_two_for_one?(code = '') ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cash_register/promotions.rb', line 13

def is_two_for_one?(code = '')
  (@promotions['TWO_FOR_ONE_FREE'] rescue []).include?(code)
end