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)
end
end
protected
def lidb_guard(params)
!params["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