~singpolyma/sgx-jmp

ref: 192d092f0a54962adf5ef067708eaacec273ce8a sgx-jmp/lib/configure_calls_form.rb -rw-r--r-- 863 bytes
192d092fStephen Paul Weber New configure calls command 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require_relative "form_to_h"

class ConfigureCallsForm
	using FormToH

	def initialize(customer)
		@customer = customer
	end

	def render
		FormTemplate.render("configure_calls", customer: @customer)
	end

	def parse(form)
		params = form.to_h
		{}.tap do |result|
			result[:fwd] = parse_fwd(params["fwd"]) if params.key?("fwd")
			if params.key?("voicemail_transcription")
				result[:transcription_enabled] =
					["1", "true"].include?(params["voicemail_transcription"])
			end
			result[:lidb_name] = params["lidb_name"] if lidb_guard(params["lidb_name"])
		end
	end

protected

	def lidb_guard(lidb_name)
		!lidb_name.to_s.strip.empty? &&
			!@customer.tndetails.dig(:features, :lidb)
	end

	def parse_fwd(fwd_from_form)
		fwd_from_form.reduce(@customer.fwd) do |fwd, (var, val)|
			fwd.with(var.to_sym => val)
		end
	end
end