@@ 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