class EtFakeCcd::EcmService

noinspection RubyStringKeysInHashInspection

Constants

OFFICE_CODE_LOOKUP
Response

Attributes

command[R]

@return [EtFakeCcd::Command::StartMultipleCommand] command

Public Class Methods

new(command) click to toggle source

@param [EtFakeCcd::Command::StartMultipleCommand] command

# File lib/et_fake_ccd/ecm_service.rb, line 26
def initialize(command)
  @command = command
end
start_multiple(command) click to toggle source

@param [EtFakeCcd::Command::StartMultipleCommand] command @return [EtFakeCcd::EcmService::Response] The response

# File lib/et_fake_ccd/ecm_service.rb, line 21
def self.start_multiple(command)
  new(command).call
end

Public Instance Methods

call() click to toggle source
# File lib/et_fake_ccd/ecm_service.rb, line 30
def call
  start_reference = adapter.reserve_reference_numbers_for(command.case_type_id, quantity: command.case_ref_number_count)
  formatted_ref = "#{office_code_for(command.case_type_id)}#{start_reference.to_s.rjust(5, '0')}/#{Time.now.year}"
  formatted_multiple = "#{office_code_for(command.case_type_id)}#{adapter.build_multiple_reference(command.case_type_id).to_s.rjust(5, '0')}/#{Time.now.year}"
  Response.new(command.case_ref_number_count, formatted_ref, formatted_multiple).freeze
end

Private Instance Methods

adapter() click to toggle source
# File lib/et_fake_ccd/ecm_service.rb, line 39
def adapter
  Thread.current[:ecm_service_adapter] ||= InMemoryAdapter.new
end
office_code_for(case_type_id) click to toggle source
# File lib/et_fake_ccd/ecm_service.rb, line 43
def office_code_for(case_type_id)
  case_type_id = case_type_id.gsub(/_Dev\z/, '')
  office_code = OFFICE_CODE_LOOKUP[case_type_id]
  raise "Case type id #{case_type_id} has no office lookup defined in the fake ccd server" if office_code.nil?

  office_code
end