embratel 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.org +15 -6
- data/lib/embratel.rb +1 -1
- data/lib/embratel/call.rb +3 -1
- data/lib/embratel/csv_parser.rb +10 -2
- data/test/embratel/call_test.rb +20 -2
- data/test/embratel/csv_parser_test.rb +2 -2
- data/test/embratel/phone_bill_test.rb +2 -2
- data/test/fixtures/valid_phone_bill_file.csv +1 -0
- metadata +1 -1
data/CHANGELOG.org
CHANGED
@@ -1,10 +1,19 @@
|
|
1
|
+
* 1.1.1
|
2
|
+
#+BEGIN_SRC
|
3
|
+
042f50e Version bump.
|
4
|
+
0e6d44b Improved exception message for parse errors.
|
5
|
+
bde08e2 Handle parsing mangled number calleds.
|
6
|
+
#+END_SRC
|
7
|
+
|
1
8
|
* 1.1.0
|
2
9
|
#+BEGIN_SRC
|
3
|
-
|
4
|
-
|
5
|
-
492dd1c Implemented the CSVParser.
|
6
|
-
c122e79 Make PhoneBill use CSVParser.
|
7
|
-
7d83b31 Better exception message for parsing errors.
|
8
|
-
37170f0 Parse and treat fees from phone bills files, too.
|
10
|
+
f770897 Version bump.
|
11
|
+
b80e49b Added CHANGELOG.
|
9
12
|
41d0a5e Reflect latest changes in the README.
|
13
|
+
37170f0 Parse and treat fees from phone bills files, too.
|
14
|
+
7d83b31 Better exception message for parsing errors.
|
15
|
+
c122e79 Make PhoneBill use CSVParser.
|
16
|
+
492dd1c Implemented the CSVParser.
|
17
|
+
b9140a4 Don't require relative
|
18
|
+
ecbfb6a Improved cost regexp, made fixture reflect moar reality.
|
10
19
|
#+END_SRC
|
data/lib/embratel.rb
CHANGED
@@ -12,7 +12,7 @@ require File.expand_path('../embratel/csv_parser', __FILE__)
|
|
12
12
|
require File.expand_path('../embratel/phone_bill', __FILE__)
|
13
13
|
|
14
14
|
module Embratel
|
15
|
-
VERSION = '1.1.
|
15
|
+
VERSION = '1.1.1'
|
16
16
|
|
17
17
|
class InvalidPhoneBillFileError < StandardError; end
|
18
18
|
class InvalidRowsError < StandardError; end
|
data/lib/embratel/call.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Embratel
|
2
2
|
class Call < Payable
|
3
|
-
|
3
|
+
MANGLED_PHONE_NUMBER_REGEXP = '\d{5}-{5}'
|
4
|
+
REGULAR_PHONE_NUMBER_REGEXP = '\d{10}'
|
5
|
+
NUMBER_CALLED_REGEXP = /^(?:#{MANGLED_PHONE_NUMBER_REGEXP}|#{REGULAR_PHONE_NUMBER_REGEXP})$/
|
4
6
|
|
5
7
|
def valid?
|
6
8
|
super && !!(number_called =~ NUMBER_CALLED_REGEXP)
|
data/lib/embratel/csv_parser.rb
CHANGED
@@ -21,15 +21,23 @@ module Embratel
|
|
21
21
|
elsif (fee = Fee.new(row)).valid?
|
22
22
|
fees << fee
|
23
23
|
else
|
24
|
-
invalid_rows << index +
|
24
|
+
invalid_rows << index + 4
|
25
25
|
end
|
26
26
|
end
|
27
27
|
if invalid_rows.empty?
|
28
28
|
calls + fees
|
29
29
|
else
|
30
|
-
raise InvalidRowsError,
|
30
|
+
raise InvalidRowsError, invalid_rows_error_message(invalid_rows)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def invalid_rows_error_message(rows)
|
38
|
+
rows.
|
39
|
+
join(', ').
|
40
|
+
insert(0, rows.size == 1 ? 'Erro na linha ' : 'Erro nas linhas ')
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
data/test/embratel/call_test.rb
CHANGED
@@ -18,9 +18,27 @@ class CallTest < Test::Unit::TestCase
|
|
18
18
|
'MIN',
|
19
19
|
'0.73']
|
20
20
|
|
21
|
+
ROW_WITH_MANGLED_NUMBER_CALLED = ['1',
|
22
|
+
'1634125644-FRANQUIA 01',
|
23
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
24
|
+
'11/08/10 A 99/99/99',
|
25
|
+
'19936-----',
|
26
|
+
'SCL -SP',
|
27
|
+
'CAS -SP',
|
28
|
+
'02:56:29 AM',
|
29
|
+
'',
|
30
|
+
'E',
|
31
|
+
'',
|
32
|
+
'500',
|
33
|
+
'MIN',
|
34
|
+
'0.73']
|
35
|
+
|
21
36
|
def test_valid_with_a_row_with_invalid_number_called
|
22
|
-
|
23
|
-
|
37
|
+
assert(!Embratel::Call.new(ROW_WITH_INVALID_NUMBER_CALLED).valid?)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_valid_with_a_row_with_mangled_number_called
|
41
|
+
assert(Embratel::Call.new(ROW_WITH_MANGLED_NUMBER_CALLED).valid?)
|
24
42
|
end
|
25
43
|
|
26
44
|
def test_valid_with_a_valid_fee_row
|
@@ -42,8 +42,8 @@ class Embratel::CSVParserTest < Test::Unit::TestCase
|
|
42
42
|
payables = Embratel::CSVParser.parse(VALID_CSV_PHONE_BILL_FILE_PATH)
|
43
43
|
calls = payables.select(&:call?)
|
44
44
|
fees = payables.select(&:fee?)
|
45
|
-
assert_equal(
|
46
|
-
assert_equal(
|
45
|
+
assert_equal(5, payables.size)
|
46
|
+
assert_equal(4, calls.size)
|
47
47
|
assert_equal(1, fees.size)
|
48
48
|
end
|
49
49
|
end
|
@@ -7,7 +7,7 @@ class Embratel::PhoneBillTest < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
def test_calls
|
9
9
|
phone_bill = Embratel::PhoneBill.new(VALID_CSV_PHONE_BILL_FILE_PATH)
|
10
|
-
assert_equal(
|
10
|
+
assert_equal(4, phone_bill.calls.size)
|
11
11
|
phone_bill.calls.each { |call| assert(call.is_a?(Embratel::Call)) }
|
12
12
|
end
|
13
13
|
|
@@ -19,6 +19,6 @@ class Embratel::PhoneBillTest < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
def test_total
|
21
21
|
phone_bill = Embratel::PhoneBill.new(VALID_CSV_PHONE_BILL_FILE_PATH)
|
22
|
-
assert_equal(11.
|
22
|
+
assert_equal(11.7, phone_bill.total)
|
23
23
|
end
|
24
24
|
end
|
@@ -5,3 +5,4 @@ Detalhes da fatura
|
|
5
5
|
2,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",1993696666,"SCL -SP ","CAS -SP ",02:59:03 AM," ","E "," ",900,"MIN ",1.3
|
6
6
|
3,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","13/08/10 A 99/99/99 ",1992566666,"SCL -SP ","CAS -SP ",09:07:55 PM," ","E "," ",5800,"MIN ",8.47
|
7
7
|
"0000004 ","10/10/91647303 ","ENCARGOS POR ATRASO REFERENTE A C.P.S. ","25/10/10 A 10/11/10 "," ","SCL -SP "," - "," "," ","N "," ","1000 ","UNID "," 1.09"
|
8
|
+
"0000032 ","1634125644-FRANQUIA 01 ","04 - LIGACOES LOCAIS PARA TELEFONES FIXOS - DURACA","99/99/99 A 99/99/99 ","16130----- ","SCL -SP ","SCL -SP "," "," ","E "," ","1000 ","MIN "," 0.11"
|