lib/embratel/phone_bill.rb in embratel-0.0.1 vs lib/embratel/phone_bill.rb in embratel-0.0.2

- old
+ new

@@ -10,11 +10,11 @@ rescue Errno::EISDIR raise rescue FasterCSV::MalformedCSVError raise else - raise InvalidPhoneBillFileError if invalid_rows? + raise InvalidPhoneBillFileError if (invalid_rows? || non_csv?(path)) end end def calls @calls ||= @csv.inject([]) do |calls, row| @@ -26,12 +26,17 @@ def total @total ||= calls.inject(0) { |sum, call| sum += call.cost.to_f } end private + def invalid_rows? csv = @csv.dup 3.times { csv.shift } csv.any? { |row| !Call.new(row).valid? } + end + + def non_csv?(path) + File.extname(path) != '.csv' end end end