embratel 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.org +62 -4
- data/embratel.gemspec +2 -3
- data/lib/embratel.rb +2 -14
- data/lib/embratel/phone_bill.rb +6 -1
- data/test/embratel/phone_bill_test.rb +10 -0
- data/test/fixtures/phone_bill.txt +0 -0
- data/test/test_helper.rb +2 -1
- metadata +7 -7
- data/lib/embratel/version.rb +0 -3
data/README.org
CHANGED
@@ -3,17 +3,75 @@
|
|
3
3
|
#+BEGIN_SRC
|
4
4
|
gem install embratel
|
5
5
|
#+END_SRC
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
Você precisa ter o ruby e o rubygems instalados.
|
7
|
+
|
8
|
+
** Uso
|
9
|
+
A Embratel fornece faturas de conta de telefone em seu
|
10
|
+
[[http://fatura.embratel.net.br/embratel/index.html][serviço online]].
|
11
|
+
Para extrair informações sobre uma fatura, você precisará do arquivo
|
12
|
+
.csv de um dado mês.
|
13
|
+
*** Como obter o arquivo da fatura?
|
14
|
+
- [[http://fatura.embratel.net.br/embratel/jsp/selectClientRegister.jsp][cadastre-se]] se você não possui uma conta
|
15
|
+
- logue no site
|
16
|
+
- escolha o mês da fatura
|
17
|
+
- vá em 'Opções' e selecione 'Exportar toda a conta'
|
18
|
+
- exporte como 'Excel - CSV'
|
19
|
+
|
20
|
+
*** Classes da gem
|
21
|
+
#+BEGIN_SRC
|
22
|
+
Embratel::PhoneBill
|
23
|
+
Embratel::Call
|
24
|
+
#+END_SRC
|
25
|
+
|
26
|
+
*** Com o arquivo da fatura você pode
|
27
|
+
#+BEGIN_SRC
|
28
|
+
phone_bill = Embratel::PhoneBill.new("/path/to/fatura.csv")
|
29
|
+
|
30
|
+
# array com todas as ligações da fatura (array de objetos Embratel::Call)
|
31
|
+
phone_bill.calls
|
32
|
+
|
33
|
+
# custo total da fatura
|
34
|
+
phone_bill.total
|
35
|
+
#+END_SRC
|
36
|
+
|
37
|
+
*** attr_accessors disponíveis para objetos Embratel::Call
|
38
|
+
#+BEGIN_SRC
|
39
|
+
id
|
40
|
+
caller
|
41
|
+
description
|
42
|
+
date
|
43
|
+
number_called
|
44
|
+
caller_local
|
45
|
+
called_local
|
46
|
+
start_time
|
47
|
+
end_time
|
48
|
+
imp
|
49
|
+
country
|
50
|
+
quantity
|
51
|
+
unit
|
52
|
+
cost
|
53
|
+
#+END_SRC
|
54
|
+
|
55
|
+
** Para rodar os testes
|
56
|
+
*** Pegue o código
|
57
|
+
#+BEGIN_SRC
|
58
|
+
git clone git://github.com/murilasso/embratel.git
|
59
|
+
cd embratel
|
60
|
+
#+END_SRC
|
61
|
+
|
62
|
+
*** Instale o bundler e as dependências (se já não estiverem instaladas)
|
9
63
|
#+BEGIN_SRC
|
10
64
|
gem install bundler
|
11
65
|
bundle install
|
66
|
+
#+END_SRC
|
67
|
+
|
68
|
+
*** Rode os testes
|
69
|
+
#+BEGIN_SRC
|
12
70
|
rake test
|
13
71
|
#+END_SRC
|
14
72
|
|
15
73
|
** Autor
|
16
|
-
[[
|
74
|
+
[[http://www.comp.ufscar.br/~murilo][Murilo Soares Pereira]]
|
17
75
|
|
18
76
|
** Licença
|
19
77
|
Distribuído sob a [[http://github.com/murilasso/embratel/blob/master/MIT-LICENSE][licença MIT]].
|
data/embratel.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path("../lib/embratel
|
2
|
+
require File.expand_path("../lib/embratel", __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "embratel"
|
@@ -8,8 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Murilo Soares Pereira"]
|
9
9
|
s.email = ["murilo.soares3@gmail.com"]
|
10
10
|
s.homepage = "http://github.com/murilasso/embratel"
|
11
|
-
s.summary = "
|
12
|
-
s.description = ""
|
11
|
+
s.summary = "Extract calls information from Embratel's phone bill files."
|
13
12
|
|
14
13
|
s.required_rubygems_version = ">= 1.3.6"
|
15
14
|
s.rubyforge_project = "embratel"
|
data/lib/embratel.rb
CHANGED
@@ -1,20 +1,8 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'bundler'
|
5
|
-
rescue LoadError
|
6
|
-
STDERR.puts "You need to install bundler"
|
7
|
-
else
|
8
|
-
begin
|
9
|
-
Bundler.setup
|
10
|
-
rescue Bundler::BundlerError
|
11
|
-
STDERR.puts $!
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
1
|
require 'embratel/phone_bill'
|
16
2
|
require 'embratel/call'
|
17
3
|
|
18
4
|
module Embratel
|
5
|
+
VERSION = "0.0.2"
|
6
|
+
|
19
7
|
class InvalidPhoneBillFileError < StandardError; end
|
20
8
|
end
|
data/lib/embratel/phone_bill.rb
CHANGED
@@ -12,7 +12,7 @@ module Embratel
|
|
12
12
|
rescue FasterCSV::MalformedCSVError
|
13
13
|
raise
|
14
14
|
else
|
15
|
-
raise InvalidPhoneBillFileError if invalid_rows?
|
15
|
+
raise InvalidPhoneBillFileError if (invalid_rows? || non_csv?(path))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -28,10 +28,15 @@ module Embratel
|
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
|
+
|
31
32
|
def invalid_rows?
|
32
33
|
csv = @csv.dup
|
33
34
|
3.times { csv.shift }
|
34
35
|
csv.any? { |row| !Call.new(row).valid? }
|
35
36
|
end
|
37
|
+
|
38
|
+
def non_csv?(path)
|
39
|
+
File.extname(path) != '.csv'
|
40
|
+
end
|
36
41
|
end
|
37
42
|
end
|
@@ -23,6 +23,10 @@ class Embratel::PhoneBillTest < Test::Unit::TestCase
|
|
23
23
|
"#{FIXTURES_PATH}/valid_phone_bill_file.csv"
|
24
24
|
end
|
25
25
|
|
26
|
+
def non_csv_phone_bill_file_path
|
27
|
+
"#{FIXTURES_PATH}/phone_bill.txt"
|
28
|
+
end
|
29
|
+
|
26
30
|
def test_phone_bill_instantiation_with_a_non_existing_file_path
|
27
31
|
assert_raise(Errno::ENOENT) { Embratel::PhoneBill.new(non_existing_file_path) }
|
28
32
|
end
|
@@ -43,6 +47,12 @@ class Embratel::PhoneBillTest < Test::Unit::TestCase
|
|
43
47
|
end
|
44
48
|
end
|
45
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
|
+
|
46
56
|
def test_phone_bill_instantiation_with_a_valid_csv_phone_bill_file_path
|
47
57
|
phone_bill = Embratel::PhoneBill.new(valid_csv_phone_bill_file_path)
|
48
58
|
assert(!phone_bill.send(:invalid_rows?))
|
File without changes
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embratel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Murilo Soares Pereira
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-05 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: 1.5.3
|
67
67
|
type: :runtime
|
68
68
|
version_requirements: *id003
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- murilo.soares3@gmail.com
|
72
72
|
executables: []
|
@@ -86,10 +86,10 @@ files:
|
|
86
86
|
- lib/embratel.rb
|
87
87
|
- lib/embratel/call.rb
|
88
88
|
- lib/embratel/phone_bill.rb
|
89
|
-
- lib/embratel/version.rb
|
90
89
|
- test/embratel/call_test.rb
|
91
90
|
- test/embratel/phone_bill_test.rb
|
92
91
|
- test/fixtures/invalid_phone_bill_file.csv
|
92
|
+
- test/fixtures/phone_bill.txt
|
93
93
|
- test/fixtures/text_file.txt
|
94
94
|
- test/fixtures/valid_phone_bill_file.csv
|
95
95
|
- test/test_helper.rb
|
@@ -128,6 +128,6 @@ rubyforge_project: embratel
|
|
128
128
|
rubygems_version: 1.3.7
|
129
129
|
signing_key:
|
130
130
|
specification_version: 3
|
131
|
-
summary:
|
131
|
+
summary: Extract calls information from Embratel's phone bill files.
|
132
132
|
test_files: []
|
133
133
|
|
data/lib/embratel/version.rb
DELETED