Class: Kaui::Bundle

Inherits:
KillBillClient::Model::Bundle
  • Object
show all
Defined in:
app/models/kaui/bundle.rb

Class Method Summary collapse

Class Method Details

.find_by_id_or_key(bundle_id_or_key, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/models/kaui/bundle.rb', line 5

def self.find_by_id_or_key(bundle_id_or_key, options = {})
  if bundle_id_or_key =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
    bundle = begin
      find_by_id(bundle_id_or_key, options)
    rescue StandardError
      nil
    end
    return bundle unless bundle.nil?
  end

  # Return the active one
  find_by_external_key(bundle_id_or_key, false, options)
end

.get_active_bundle_or_latest_created(bundles, time_zone = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/kaui/bundle.rb', line 27

def self.get_active_bundle_or_latest_created(bundles, time_zone = nil)
  return nil if bundles.empty?

  latest_start_date = nil
  latest_bundle     = nil

  bundles.each do |b|
    b.subscriptions.each do |s|
      next unless s.product_category != 'ADD_ON'

      if latest_start_date.nil? || latest_start_date < s.start_date
        latest_start_date = s.start_date
        latest_bundle     = b
      end

      return b if s.cancelled_date.nil? || s.cancelled_date > ActionController::Base.helpers.current_time(time_zone)
    end
  end

  latest_bundle
end

.list_or_search(search_key = nil, offset = 0, limit = 10, options = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'app/models/kaui/bundle.rb', line 19

def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
  if search_key.present?
    find_in_batches_by_search_key(search_key, offset, limit, options)
  else
    find_in_batches(offset, limit, options)
  end
end

.list_transfer_policy_paramsObject



49
50
51
52
53
54
55
# File 'app/models/kaui/bundle.rb', line 49

def self.list_transfer_policy_params
  @policy_params = [
    [I18n.translate('start_of_term'), 'START_OF_TERM'],
    [I18n.translate('end_of_term'), 'END_OF_TERM'],
    [I18n.translate('immediate'), 'IMMEDIATE']
  ]
end

.list_transfer_policy_params_keysObject



57
58
59
# File 'app/models/kaui/bundle.rb', line 57

def self.list_transfer_policy_params_keys
  @policy_params = %w[START_OF_TERM END_OF_TERM IMMEDIATE]
end