class Lita::Interactors::InscribeCustomer
Inscribes a customer in a service
Attributes
data[R]
Public Class Methods
new(handler, data)
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 12 def initialize(handler, data) @handler = handler @data = data end
Public Instance Methods
perform()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 17 def perform if service_exists? inscribe_customer_if_new else @error = msg_not_found(service_name: name) end self end
Private Instance Methods
add_customer()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 61 def add_customer service[:customers][customer_name.to_sym] = customer repository.update(service) @message = I18n.t('lita.handlers.service.inscribe.success', service_name: name, customer_name: customer_name) end
calculate_value()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 75 def calculate_value return customer_value.to_i unless customer_value.empty? service[:value] end
customer()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 68 def customer { quantity: 0, value: calculate_value } end
customer_name()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 32 def customer_name @customer_name ||= data[2].delete('@') end
customer_value()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 36 def customer_value @customer_value ||= data[3].to_s end
inscribe_customer_if_new()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 52 def inscribe_customer_if_new if new_customer? add_customer else @error = msg_customer_duplicated(service_name: name, customer_name: customer_name) end end
name()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 28 def name @name ||= data[1] end
new_customer?()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 48 def new_customer? !service[:customers].keys.include?(customer_name.to_sym) end
service()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 40 def service @service ||= repository.find(name) end
service_exists?()
click to toggle source
# File lib/lita/interactors/inscribe_customer.rb, line 44 def service_exists? repository.exists?(name) end