~singpolyma/sgx-jmp

a268e15e906522ab44bfd5a32da8bb99140d11f4 — Stephen Paul Weber 1 year, 8 months ago 07c9c58
Make Disposition more real
1 files changed, 20 insertions(+), 16 deletions(-)

M lib/cdr.rb
M lib/cdr.rb => lib/cdr.rb +20 -16
@@ 3,12 3,31 @@
require "value_semantics/monkey_patched"

class CDR
	module Disposition
		def self.===(other)
			["NO ANSWER", "ANSWERED", "BUSY", "FAILED"].include?(other)
		end

		def self.for(cause)
			case cause
			when "timeout", "rejected", "cancel"
				"NO ANSWER"
			when "hangup"
				"ANSWERED"
			when "busy"
				"BUSY"
			else
				"FAILED"
			end
		end
	end

	value_semantics do
		cdr_id String
		customer_id String
		start Time
		billsec Integer
		disposition Either("NO ANSWER", "ANSWERED", "BUSY", "FAILED")
		disposition Disposition
		tel(/\A\+\d+\Z/)
		direction Either(:inbound, :outbound)
	end


@@ 49,19 68,4 @@ class CDR
			VALUES ($1, $2, $3, $4, $5, $6, $7)
		SQL
	end

	module Disposition
		def self.for(cause)
			case cause
			when "timeout", "rejected", "cancel"
				"NO ANSWER"
			when "hangup"
				"ANSWERED"
			when "busy"
				"BUSY"
			else
				"FAILED"
			end
		end
	end
end