diff --git a/lib/cdr.rb b/lib/cdr.rb index b8077378605cdd995d06fff3ada51ceebfd14e77..de9d1f43cc58fd37a5368349181a7b2c092d0c2a 100644 --- a/lib/cdr.rb +++ b/lib/cdr.rb @@ -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