embratel 1.0.0 → 1.1.0
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 +10 -0
- data/README.org +9 -10
- data/lib/embratel.rb +9 -3
- data/lib/embratel/call.rb +2 -29
- data/lib/embratel/csv_parser.rb +35 -0
- data/lib/embratel/fee.rb +7 -0
- data/lib/embratel/payable.rb +41 -0
- data/lib/embratel/phone_bill.rb +8 -27
- data/test/embratel/call_test.rb +38 -94
- data/test/embratel/csv_parser_test.rb +49 -0
- data/test/embratel/fee_test.rb +48 -0
- data/test/embratel/payable_test.rb +87 -0
- data/test/embratel/phone_bill_test.rb +13 -59
- data/test/fixtures/{text_file.txt → lorem_ipsum.csv} +0 -0
- data/test/fixtures/valid_phone_bill_file.csv +7 -6
- data/test/test_helper.rb +31 -4
- metadata +10 -3
data/CHANGELOG.org
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
* 1.1.0
|
2
|
+
#+BEGIN_SRC
|
3
|
+
ecbfb6a Improved cost regexp, made fixture reflect moar reality.
|
4
|
+
b9140a4 Don't require relative
|
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.
|
9
|
+
41d0a5e Reflect latest changes in the README.
|
10
|
+
#+END_SRC
|
data/README.org
CHANGED
@@ -17,25 +17,24 @@ $ gem install embratel
|
|
17
17
|
- vá em 'Opções' e selecione 'Exportar toda a conta'
|
18
18
|
- exporte como 'Excel - CSV'
|
19
19
|
|
20
|
-
*** Classes da gem
|
21
|
-
#+BEGIN_SRC
|
22
|
-
Embratel::PhoneBill
|
23
|
-
Embratel::Call
|
24
|
-
#+END_SRC
|
25
|
-
|
26
20
|
*** Com o arquivo da fatura você pode
|
27
21
|
#+BEGIN_SRC
|
28
|
-
# Instancie uma fatura.
|
29
22
|
>> phone_bill = Embratel::PhoneBill.new("/path/to/fatura.csv")
|
30
23
|
|
31
|
-
#
|
24
|
+
# Array com todas as ligações da fatura (objetos Embratel::Call).
|
32
25
|
>> phone_bill.calls
|
33
26
|
|
34
|
-
#
|
27
|
+
# Array com todas as taxas da fatura (objetos Embratel::Fee).
|
28
|
+
>> phone_bill.fees
|
29
|
+
|
30
|
+
# Array com todas as ligações e taxas da fatura.
|
31
|
+
>> phone_bill.payables
|
32
|
+
|
33
|
+
# Custo total da fatura.
|
35
34
|
>> phone_bill.total
|
36
35
|
#+END_SRC
|
37
36
|
|
38
|
-
*** attr_accessors disponíveis para objetos Embratel::Call
|
37
|
+
*** attr_accessors disponíveis para objetos Embratel::Call e Embratel::Fee
|
39
38
|
#+BEGIN_SRC
|
40
39
|
id
|
41
40
|
caller
|
data/lib/embratel.rb
CHANGED
@@ -5,11 +5,17 @@ else
|
|
5
5
|
require 'csv'
|
6
6
|
end
|
7
7
|
|
8
|
-
require 'embratel/
|
9
|
-
require 'embratel/
|
8
|
+
require File.expand_path('../embratel/payable', __FILE__)
|
9
|
+
require File.expand_path('../embratel/call', __FILE__)
|
10
|
+
require File.expand_path('../embratel/fee', __FILE__)
|
11
|
+
require File.expand_path('../embratel/csv_parser', __FILE__)
|
12
|
+
require File.expand_path('../embratel/phone_bill', __FILE__)
|
10
13
|
|
11
14
|
module Embratel
|
12
|
-
VERSION = '1.
|
15
|
+
VERSION = '1.1.0'
|
13
16
|
|
14
17
|
class InvalidPhoneBillFileError < StandardError; end
|
18
|
+
class InvalidRowsError < StandardError; end
|
19
|
+
class NonCSVFileError < StandardError; end
|
20
|
+
class InvalidCSVFileError < StandardError; end
|
15
21
|
end
|
data/lib/embratel/call.rb
CHANGED
@@ -1,36 +1,9 @@
|
|
1
1
|
module Embratel
|
2
|
-
class Call
|
2
|
+
class Call < Payable
|
3
3
|
NUMBER_CALLED_REGEXP = /^\d{10}$/
|
4
|
-
COST_REGEXP = /^\d*(\.\d+)?$/
|
5
|
-
FIELDS = %w[id
|
6
|
-
caller
|
7
|
-
description
|
8
|
-
date
|
9
|
-
number_called
|
10
|
-
caller_local
|
11
|
-
called_local
|
12
|
-
start_time
|
13
|
-
end_time
|
14
|
-
imp
|
15
|
-
country
|
16
|
-
quantity
|
17
|
-
unit
|
18
|
-
cost]
|
19
|
-
|
20
|
-
FIELDS.each { |field| attr_accessor field.to_sym }
|
21
|
-
|
22
|
-
def initialize(csv_row)
|
23
|
-
@csv_row_size = csv_row.size
|
24
|
-
|
25
|
-
FIELDS.each_with_index do |field, index|
|
26
|
-
instance_variable_set("@#{field}".to_sym, csv_row[index].to_s.strip)
|
27
|
-
end
|
28
|
-
end
|
29
4
|
|
30
5
|
def valid?
|
31
|
-
|
32
|
-
number_called =~ NUMBER_CALLED_REGEXP &&
|
33
|
-
cost =~ COST_REGEXP
|
6
|
+
super && !!(number_called =~ NUMBER_CALLED_REGEXP)
|
34
7
|
end
|
35
8
|
end
|
36
9
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Embratel
|
4
|
+
module CSVParser
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def parse(path)
|
8
|
+
rows = CSV.read(path, { :skip_blanks => true })
|
9
|
+
rescue Errno::ENOENT, Errno::EISDIR, CSV::MalformedCSVError
|
10
|
+
raise
|
11
|
+
else
|
12
|
+
if File.extname(path) != '.csv'
|
13
|
+
raise NonCSVFileError
|
14
|
+
else
|
15
|
+
# Skipping title and header lines.
|
16
|
+
2.times { rows.shift }
|
17
|
+
invalid_rows, calls, fees = [], [], []
|
18
|
+
rows.each_with_index do |row, index|
|
19
|
+
if (call = Call.new(row)).valid?
|
20
|
+
calls << call
|
21
|
+
elsif (fee = Fee.new(row)).valid?
|
22
|
+
fees << fee
|
23
|
+
else
|
24
|
+
invalid_rows << index + 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
if invalid_rows.empty?
|
28
|
+
calls + fees
|
29
|
+
else
|
30
|
+
raise InvalidRowsError, "Erro nas linhas #{invalid_rows.join(', ')}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/embratel/fee.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Embratel
|
2
|
+
class Payable
|
3
|
+
COST_REGEXP = /^\d+(?:\.\d+)?$/
|
4
|
+
FIELDS = %w[id
|
5
|
+
caller
|
6
|
+
description
|
7
|
+
date
|
8
|
+
number_called
|
9
|
+
caller_local
|
10
|
+
called_local
|
11
|
+
start_time
|
12
|
+
end_time
|
13
|
+
imp
|
14
|
+
country
|
15
|
+
quantity
|
16
|
+
unit
|
17
|
+
cost]
|
18
|
+
|
19
|
+
FIELDS.each { |field| attr_accessor field.to_sym }
|
20
|
+
|
21
|
+
def initialize(row)
|
22
|
+
@row = row
|
23
|
+
|
24
|
+
FIELDS.each_with_index do |field, index|
|
25
|
+
instance_variable_set("@#{field}".to_sym, row[index].to_s.strip)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def call?
|
30
|
+
is_a?(Call)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fee?
|
34
|
+
is_a?(Fee)
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid?
|
38
|
+
@row.size == 14 && !!(cost =~ COST_REGEXP)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/embratel/phone_bill.rb
CHANGED
@@ -1,40 +1,21 @@
|
|
1
1
|
module Embratel
|
2
2
|
class PhoneBill
|
3
|
+
attr_reader :payables
|
4
|
+
|
3
5
|
def initialize(path)
|
4
|
-
|
5
|
-
@csv = CSV.read(path, { :skip_blanks => true })
|
6
|
-
rescue Errno::ENOENT
|
7
|
-
raise
|
8
|
-
rescue Errno::EISDIR
|
9
|
-
raise
|
10
|
-
rescue CSV::MalformedCSVError
|
11
|
-
raise
|
12
|
-
else
|
13
|
-
raise InvalidPhoneBillFileError if (invalid_rows? || non_csv?(path))
|
14
|
-
end
|
6
|
+
@payables = CSVParser.parse(path)
|
15
7
|
end
|
16
8
|
|
17
9
|
def calls
|
18
|
-
@calls ||= @
|
19
|
-
call = Call.new(row)
|
20
|
-
call.valid? ? (calls << call) : calls
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def total
|
25
|
-
@total ||= calls.inject(0) { |sum, call| sum += call.cost.to_f }
|
10
|
+
@calls ||= @payables.select(&:call?)
|
26
11
|
end
|
27
12
|
|
28
|
-
|
29
|
-
|
30
|
-
def invalid_rows?
|
31
|
-
csv = @csv.dup
|
32
|
-
3.times { csv.shift }
|
33
|
-
csv.any? { |row| !Call.new(row).valid? }
|
13
|
+
def fees
|
14
|
+
@calls ||= @payables.select(&:fee?)
|
34
15
|
end
|
35
16
|
|
36
|
-
def
|
37
|
-
|
17
|
+
def total
|
18
|
+
@total ||= payables.inject(0) { |sum, payable| sum += payable.cost.to_f }
|
38
19
|
end
|
39
20
|
end
|
40
21
|
end
|
data/test/embratel/call_test.rb
CHANGED
@@ -1,104 +1,48 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
class CallTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
'04 - LIGACOES DDD PARA CELULARES',
|
24
|
-
'11/08/10 A 99/99/99',
|
25
|
-
'19936928871',
|
26
|
-
'SCL -SP',
|
27
|
-
'CAS -SP',
|
28
|
-
'02:56:29 AM',
|
29
|
-
'',
|
30
|
-
'E',
|
31
|
-
'',
|
32
|
-
'500',
|
33
|
-
'MIN',
|
34
|
-
'0.73']
|
35
|
-
end
|
36
|
-
|
37
|
-
def row_with_invalid_cost
|
38
|
-
['1',
|
39
|
-
'1634125644-FRANQUIA 01',
|
40
|
-
'04 - LIGACOES DDD PARA CELULARES',
|
41
|
-
'11/08/10 A 99/99/99',
|
42
|
-
'19936928871',
|
43
|
-
'SCL -SP',
|
44
|
-
'CAS -SP',
|
45
|
-
'02:56:29 AM',
|
46
|
-
'',
|
47
|
-
'E',
|
48
|
-
'',
|
49
|
-
'500',
|
50
|
-
'MIN',
|
51
|
-
'.73']
|
52
|
-
end
|
53
|
-
|
54
|
-
def valid_row
|
55
|
-
['1',
|
56
|
-
'1634125644-FRANQUIA 01',
|
57
|
-
'04 - LIGACOES DDD PARA CELULARES',
|
58
|
-
'11/08/10 A 99/99/99',
|
59
|
-
'1993692887',
|
60
|
-
'SCL -SP',
|
61
|
-
'CAS -SP',
|
62
|
-
'02:56:29 AM',
|
63
|
-
'',
|
64
|
-
'E',
|
65
|
-
'',
|
66
|
-
'500',
|
67
|
-
'MIN',
|
68
|
-
'0.73']
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_call_instantiated_with_a_row_with_a_missing_field
|
72
|
-
call = Embratel::Call.new(row_with_a_missing_field)
|
73
|
-
assert(!call.valid?)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_call_instantiated_with_a_row_with_invalid_number_called
|
77
|
-
call = Embratel::Call.new(row_with_invalid_number_called)
|
4
|
+
include ValidRows
|
5
|
+
|
6
|
+
ROW_WITH_INVALID_NUMBER_CALLED = ['1',
|
7
|
+
'1634125644-FRANQUIA 01',
|
8
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
9
|
+
'11/08/10 A 99/99/99',
|
10
|
+
'19936928871',
|
11
|
+
'SCL -SP',
|
12
|
+
'CAS -SP',
|
13
|
+
'02:56:29 AM',
|
14
|
+
'',
|
15
|
+
'E',
|
16
|
+
'',
|
17
|
+
'500',
|
18
|
+
'MIN',
|
19
|
+
'0.73']
|
20
|
+
|
21
|
+
def test_valid_with_a_row_with_invalid_number_called
|
22
|
+
call = Embratel::Call.new(ROW_WITH_INVALID_NUMBER_CALLED)
|
78
23
|
assert(!call.valid?)
|
79
24
|
end
|
80
25
|
|
81
|
-
def
|
82
|
-
|
83
|
-
assert(!call.valid?)
|
26
|
+
def test_valid_with_a_valid_fee_row
|
27
|
+
assert(!Embratel::Call.new(VALID_FEE_ROW).valid?)
|
84
28
|
end
|
85
29
|
|
86
|
-
def
|
87
|
-
call = Embratel::Call.new(
|
30
|
+
def test_valid_with_a_valid_call_row
|
31
|
+
call = Embratel::Call.new(VALID_CALL_ROW)
|
88
32
|
assert(call.valid?)
|
89
|
-
assert_equal(call.id
|
90
|
-
assert_equal(
|
91
|
-
assert_equal(
|
92
|
-
assert_equal(
|
93
|
-
assert_equal(call.number_called
|
94
|
-
assert_equal(
|
95
|
-
assert_equal(
|
96
|
-
assert_equal(
|
97
|
-
assert_equal(call.end_time
|
98
|
-
assert_equal(call.imp
|
99
|
-
assert_equal(call.country
|
100
|
-
assert_equal(call.quantity
|
101
|
-
assert_equal(call.unit
|
102
|
-
assert_equal(
|
33
|
+
assert_equal('1', call.id)
|
34
|
+
assert_equal('1634125644-FRANQUIA 01', call.caller)
|
35
|
+
assert_equal('04 - LIGACOES DDD PARA CELULARES', call.description)
|
36
|
+
assert_equal('11/08/10 A 99/99/99', call.date)
|
37
|
+
assert_equal('1993692887', call.number_called)
|
38
|
+
assert_equal('SCL -SP', call.caller_local)
|
39
|
+
assert_equal('CAS -SP', call.called_local)
|
40
|
+
assert_equal('02:56:29 AM', call.start_time)
|
41
|
+
assert_equal('', call.end_time)
|
42
|
+
assert_equal('E', call.imp)
|
43
|
+
assert_equal('', call.country)
|
44
|
+
assert_equal('500', call.quantity)
|
45
|
+
assert_equal('MIN', call.unit)
|
46
|
+
assert_equal('0.73', call.cost)
|
103
47
|
end
|
104
48
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class Embratel::CSVParserTest < Test::Unit::TestCase
|
4
|
+
FIXTURES_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
5
|
+
|
6
|
+
NON_EXISTING_FILE_PATH = "#{FIXTURES_PATH}/non_existing_file.csv"
|
7
|
+
DIRECTORY_PATH = "#{FIXTURES_PATH}"
|
8
|
+
NON_PHONE_BILL_FILE_PATH = "#{FIXTURES_PATH}/lorem_ipsum.csv"
|
9
|
+
INVALID_CSV_PHONE_BILL_FILE_PATH = "#{FIXTURES_PATH}/invalid_phone_bill_file.csv"
|
10
|
+
VALID_CSV_PHONE_BILL_FILE_PATH = "#{FIXTURES_PATH}/valid_phone_bill_file.csv"
|
11
|
+
NON_CSV_PHONE_BILL_FILE_PATH = "#{FIXTURES_PATH}/phone_bill.txt"
|
12
|
+
|
13
|
+
def test_csv_parser_instantiation_with_a_non_existing_file_path
|
14
|
+
assert_raise(Errno::ENOENT) do
|
15
|
+
Embratel::CSVParser.parse(NON_EXISTING_FILE_PATH)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_csv_parser_instantiation_with_a_directory_path
|
20
|
+
assert_raise(Errno::EISDIR) { Embratel::CSVParser.parse(DIRECTORY_PATH) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_csv_parser_instantiation_with_a_non_phone_bill_file_path
|
24
|
+
assert_raise(Embratel::InvalidRowsError) do
|
25
|
+
Embratel::CSVParser.parse(NON_PHONE_BILL_FILE_PATH)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_csv_parser_instantiation_with_an_invalid_csv_phone_bill_file
|
30
|
+
assert_raise(Embratel::InvalidRowsError) do
|
31
|
+
Embratel::CSVParser.parse(INVALID_CSV_PHONE_BILL_FILE_PATH)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_does_not_allow_other_file_extensions_than_csv
|
36
|
+
assert_raise(Embratel::NonCSVFileError) do
|
37
|
+
Embratel::CSVParser.parse(NON_CSV_PHONE_BILL_FILE_PATH)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_parse_with_valid_phone_bill_file
|
42
|
+
payables = Embratel::CSVParser.parse(VALID_CSV_PHONE_BILL_FILE_PATH)
|
43
|
+
calls = payables.select(&:call?)
|
44
|
+
fees = payables.select(&:fee?)
|
45
|
+
assert_equal(4, payables.size)
|
46
|
+
assert_equal(3, calls.size)
|
47
|
+
assert_equal(1, fees.size)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class FeeTest < Test::Unit::TestCase
|
4
|
+
include ValidRows
|
5
|
+
|
6
|
+
ROW_WITH_NUMBER_CALLED = ['1',
|
7
|
+
'1634125644-FRANQUIA 01',
|
8
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
9
|
+
'11/08/10 A 99/99/99',
|
10
|
+
'19936928871',
|
11
|
+
'SCL -SP',
|
12
|
+
'CAS -SP',
|
13
|
+
'02:56:29 AM',
|
14
|
+
'',
|
15
|
+
'E',
|
16
|
+
'',
|
17
|
+
'500',
|
18
|
+
'MIN',
|
19
|
+
'0.73']
|
20
|
+
|
21
|
+
def test_valid_with_a_row_with_number_called
|
22
|
+
fee = Embratel::Fee.new(ROW_WITH_NUMBER_CALLED)
|
23
|
+
assert(!fee.valid?)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_valid_with_a_valid_call_row
|
27
|
+
assert(!Embratel::Fee.new(VALID_CALL_ROW).valid?)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_valid_with_a_valid_fee_row
|
31
|
+
fee = Embratel::Fee.new(VALID_FEE_ROW)
|
32
|
+
assert(fee.valid?)
|
33
|
+
assert_equal('1', fee.id)
|
34
|
+
assert_equal('1634125644-FRANQUIA 01', fee.caller)
|
35
|
+
assert_equal('04 - LIGACOES DDD PARA CELULARES', fee.description)
|
36
|
+
assert_equal('11/08/10 A 99/99/99', fee.date)
|
37
|
+
assert_equal('', fee.number_called)
|
38
|
+
assert_equal('SCL -SP', fee.caller_local)
|
39
|
+
assert_equal('CAS -SP', fee.called_local)
|
40
|
+
assert_equal('02:56:29 AM', fee.start_time)
|
41
|
+
assert_equal('', fee.end_time)
|
42
|
+
assert_equal('E', fee.imp)
|
43
|
+
assert_equal('', fee.country)
|
44
|
+
assert_equal('500', fee.quantity)
|
45
|
+
assert_equal('MIN', fee.unit)
|
46
|
+
assert_equal('0.73', fee.cost)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class PayableTest < Test::Unit::TestCase
|
4
|
+
include ValidRows
|
5
|
+
|
6
|
+
ROW_WITH_A_MISSING_FIELD = ['1',
|
7
|
+
'1634125644-FRANQUIA 01',
|
8
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
9
|
+
'11/08/10 A 99/99/99',
|
10
|
+
'SCL -SP',
|
11
|
+
'CAS -SP',
|
12
|
+
'02:56:29 AM',
|
13
|
+
'',
|
14
|
+
'E',
|
15
|
+
'',
|
16
|
+
'500',
|
17
|
+
'MIN',
|
18
|
+
'0.73']
|
19
|
+
|
20
|
+
ROW_WITH_INVALID_COST = ['1',
|
21
|
+
'1634125644-FRANQUIA 01',
|
22
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
23
|
+
'11/08/10 A 99/99/99',
|
24
|
+
'19936928871',
|
25
|
+
'SCL -SP',
|
26
|
+
'CAS -SP',
|
27
|
+
'02:56:29 AM',
|
28
|
+
'',
|
29
|
+
'E',
|
30
|
+
'',
|
31
|
+
'500',
|
32
|
+
'MIN',
|
33
|
+
'.73']
|
34
|
+
|
35
|
+
ROW_WITH_COST_WITH_SPACES_IN_THE_BEGINNING = ['1',
|
36
|
+
'1634125644-FRANQUIA 01',
|
37
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
38
|
+
'11/08/10 A 99/99/99',
|
39
|
+
'1993692887',
|
40
|
+
'SCL -SP',
|
41
|
+
'CAS -SP',
|
42
|
+
'02:56:29 AM',
|
43
|
+
'',
|
44
|
+
'E',
|
45
|
+
'',
|
46
|
+
'500',
|
47
|
+
'MIN',
|
48
|
+
' 0.73']
|
49
|
+
|
50
|
+
def test_call_with_call
|
51
|
+
assert(Embratel::Call.new(VALID_CALL_ROW).call?)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_call_with_fee
|
55
|
+
assert(!Embratel::Fee.new(VALID_FEE_ROW).call?)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_fee_with_fee
|
59
|
+
assert(Embratel::Fee.new(VALID_FEE_ROW).fee?)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_fee_with_call
|
63
|
+
assert(!Embratel::Call.new(VALID_CALL_ROW).fee?)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_valid_with_a_row_with_a_missing_field
|
67
|
+
assert(!Embratel::Payable.new(ROW_WITH_A_MISSING_FIELD).valid?)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_valid_with_a_row_with_invalid_cost
|
71
|
+
assert(!Embratel::Payable.new(ROW_WITH_INVALID_COST).valid?)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_valid_with_row_with_cost_with_spaces_in_the_beginning
|
75
|
+
payable = Embratel::Payable.new(ROW_WITH_COST_WITH_SPACES_IN_THE_BEGINNING)
|
76
|
+
assert(payable.valid?)
|
77
|
+
assert_equal('0.73', payable.cost)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_valid_with_a_valid_call_row
|
81
|
+
assert(Embratel::Payable.new(VALID_CALL_ROW).valid?)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_valid_with_a_valid_fee_row
|
85
|
+
assert(Embratel::Payable.new(VALID_FEE_ROW).valid?)
|
86
|
+
end
|
87
|
+
end
|
@@ -1,70 +1,24 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
class Embratel::PhoneBillTest < Test::Unit::TestCase
|
4
4
|
FIXTURES_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
5
5
|
|
6
|
-
|
7
|
-
"#{FIXTURES_PATH}/non_existing_file.csv"
|
8
|
-
end
|
9
|
-
|
10
|
-
def directory_path
|
11
|
-
"#{FIXTURES_PATH}"
|
12
|
-
end
|
13
|
-
|
14
|
-
def non_phone_bill_file_path
|
15
|
-
"#{FIXTURES_PATH}/text_file.txt"
|
16
|
-
end
|
17
|
-
|
18
|
-
def invalid_csv_phone_bill_file_path
|
19
|
-
"#{FIXTURES_PATH}/invalid_phone_bill_file.csv"
|
20
|
-
end
|
21
|
-
|
22
|
-
def valid_csv_phone_bill_file_path
|
23
|
-
"#{FIXTURES_PATH}/valid_phone_bill_file.csv"
|
24
|
-
end
|
6
|
+
VALID_CSV_PHONE_BILL_FILE_PATH = "#{FIXTURES_PATH}/valid_phone_bill_file.csv"
|
25
7
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def test_phone_bill_instantiation_with_a_non_existing_file_path
|
31
|
-
assert_raise(Errno::ENOENT) { Embratel::PhoneBill.new(non_existing_file_path) }
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_phone_bill_instantiation_with_a_directory_path
|
35
|
-
assert_raise(Errno::EISDIR) { Embratel::PhoneBill.new(directory_path) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_phone_bill_instantiation_with_a_non_phone_bill_file_path
|
39
|
-
assert_raise(Embratel::InvalidPhoneBillFileError) do
|
40
|
-
Embratel::PhoneBill.new(non_phone_bill_file_path)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_phone_bill_instantiation_with_an_invalid_csv_phone_bill_file_path
|
45
|
-
assert_raise(Embratel::InvalidPhoneBillFileError) do
|
46
|
-
Embratel::PhoneBill.new(invalid_csv_phone_bill_file_path)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_does_not_allow_other_file_extensions_than_csv
|
51
|
-
assert_raise(Embratel::InvalidPhoneBillFileError) do
|
52
|
-
Embratel::PhoneBill.new(non_csv_phone_bill_file_path)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_phone_bill_instantiation_with_a_valid_csv_phone_bill_file_path
|
57
|
-
phone_bill = Embratel::PhoneBill.new(valid_csv_phone_bill_file_path)
|
58
|
-
assert(!phone_bill.send(:invalid_rows?))
|
8
|
+
def test_calls
|
9
|
+
phone_bill = Embratel::PhoneBill.new(VALID_CSV_PHONE_BILL_FILE_PATH)
|
10
|
+
assert_equal(3, phone_bill.calls.size)
|
11
|
+
phone_bill.calls.each { |call| assert(call.is_a?(Embratel::Call)) }
|
59
12
|
end
|
60
13
|
|
61
|
-
def
|
62
|
-
phone_bill = Embratel::PhoneBill.new(
|
63
|
-
assert_equal(
|
14
|
+
def test_fees
|
15
|
+
phone_bill = Embratel::PhoneBill.new(VALID_CSV_PHONE_BILL_FILE_PATH)
|
16
|
+
assert_equal(1, phone_bill.fees.size)
|
17
|
+
phone_bill.fees.each { |fee| assert(fee.is_a?(Embratel::Fee)) }
|
64
18
|
end
|
65
19
|
|
66
|
-
def
|
67
|
-
phone_bill = Embratel::PhoneBill.new(
|
68
|
-
assert_equal(
|
20
|
+
def test_total
|
21
|
+
phone_bill = Embratel::PhoneBill.new(VALID_CSV_PHONE_BILL_FILE_PATH)
|
22
|
+
assert_equal(11.59, phone_bill.total)
|
69
23
|
end
|
70
24
|
end
|
File without changes
|
@@ -1,6 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
"Seq ","Origem ","
|
4
|
-
1,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",
|
5
|
-
2,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",
|
6
|
-
3,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","13/08/10 A 99/99/99 ",
|
1
|
+
Detalhes da fatura
|
2
|
+
|
3
|
+
"Seq ","Origem ","Descrição ","Periodo/Data ","Terminal_Destino ","Local Origem","Local Destino ","Hora Inicio ","Hora Fim ","Imp ","Pais ","Qtde ","Unid ","Valor (R$) "
|
4
|
+
1,"1634125644-FRANQUIA 01 ","04 - LIGACOES DDD PARA CELULARES ","11/08/10 A 99/99/99 ",1993696666,"SCL -SP ","CAS -SP ",02:56:29 AM," ","E "," ",500,"MIN ",0.73
|
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
|
+
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
|
+
"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"
|
data/test/test_helper.rb
CHANGED
@@ -1,7 +1,34 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'embratel'
|
1
|
+
require File.expand_path('../../lib/embratel.rb', __FILE__)
|
4
2
|
require 'test/unit'
|
5
3
|
|
6
|
-
|
4
|
+
module ValidRows
|
5
|
+
VALID_CALL_ROW = ['1',
|
6
|
+
'1634125644-FRANQUIA 01',
|
7
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
8
|
+
'11/08/10 A 99/99/99',
|
9
|
+
'1993692887',
|
10
|
+
'SCL -SP',
|
11
|
+
'CAS -SP',
|
12
|
+
'02:56:29 AM',
|
13
|
+
'',
|
14
|
+
'E',
|
15
|
+
'',
|
16
|
+
'500',
|
17
|
+
'MIN',
|
18
|
+
'0.73']
|
19
|
+
|
20
|
+
VALID_FEE_ROW = ['1',
|
21
|
+
'1634125644-FRANQUIA 01',
|
22
|
+
'04 - LIGACOES DDD PARA CELULARES',
|
23
|
+
'11/08/10 A 99/99/99',
|
24
|
+
'',
|
25
|
+
'SCL -SP',
|
26
|
+
'CAS -SP',
|
27
|
+
'02:56:29 AM',
|
28
|
+
'',
|
29
|
+
'E',
|
30
|
+
'',
|
31
|
+
'500',
|
32
|
+
'MIN',
|
33
|
+
'0.73']
|
7
34
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: embratel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Murilo Pereira
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-22 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -46,6 +46,7 @@ extra_rdoc_files: []
|
|
46
46
|
files:
|
47
47
|
- .gitignore
|
48
48
|
- .rvmrc
|
49
|
+
- CHANGELOG.org
|
49
50
|
- Gemfile
|
50
51
|
- Gemfile.lock
|
51
52
|
- MIT-LICENSE
|
@@ -54,12 +55,18 @@ files:
|
|
54
55
|
- embratel.gemspec
|
55
56
|
- lib/embratel.rb
|
56
57
|
- lib/embratel/call.rb
|
58
|
+
- lib/embratel/csv_parser.rb
|
59
|
+
- lib/embratel/fee.rb
|
60
|
+
- lib/embratel/payable.rb
|
57
61
|
- lib/embratel/phone_bill.rb
|
58
62
|
- test/embratel/call_test.rb
|
63
|
+
- test/embratel/csv_parser_test.rb
|
64
|
+
- test/embratel/fee_test.rb
|
65
|
+
- test/embratel/payable_test.rb
|
59
66
|
- test/embratel/phone_bill_test.rb
|
60
67
|
- test/fixtures/invalid_phone_bill_file.csv
|
68
|
+
- test/fixtures/lorem_ipsum.csv
|
61
69
|
- test/fixtures/phone_bill.txt
|
62
|
-
- test/fixtures/text_file.txt
|
63
70
|
- test/fixtures/valid_phone_bill_file.csv
|
64
71
|
- test/test_helper.rb
|
65
72
|
has_rdoc: true
|