brunossilveira-profiler 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rake_tasks +23 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.md +27 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/profiler +5 -0
- data/brunossilveira-profiler.gemspec +80 -0
- data/lib/brunossilveira-profiler.rb +19 -0
- data/lib/models/row.rb +39 -0
- data/lib/services/profiler_service.rb +28 -0
- data/lib/utils/mapper.rb +45 -0
- data/lib/utils/messages.rb +6 -0
- data/lib/utils/parser.rb +29 -0
- data/lib/utils/profiler.rb +72 -0
- data/spec/models/row_spec.rb +39 -0
- data/spec/services/profiler_service_spec.rb +4 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/test.csv +6 -0
- data/spec/utils/mapper_spec.rb +28 -0
- data/spec/utils/parser_spec.rb +40 -0
- data/spec/utils/profiler_spec.rb +61 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68d1cb4e978cd1a4859e4b131ef65e0f721873ea
|
4
|
+
data.tar.gz: 2ca1cda48cd43f77cf2c1c53cb9ce0b851bee8ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5e91aef69e8c270e9c7b96d8e0567ad3b209f4a3875aa792ebcfa727c0ce7f89d63e7ec2fd6ef577908839e38d7cf54039cae23798b622d32fdf6e8a0e3b26b6
|
7
|
+
data.tar.gz: 7efe984b29e1fc829a19b3a0e1811c10b01e54990f6d30d37e38e7413699f4c9456f47348e36db67e955242498ab47b9a42598f0f6da75bff1a95de4dec92abb
|
data/.document
ADDED
data/.rake_tasks
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
build
|
2
|
+
clean
|
3
|
+
clobber
|
4
|
+
clobber_rdoc
|
5
|
+
console[script]
|
6
|
+
gemcutter:release
|
7
|
+
gemspec
|
8
|
+
gemspec:debug
|
9
|
+
gemspec:generate
|
10
|
+
gemspec:release
|
11
|
+
gemspec:validate
|
12
|
+
git:release
|
13
|
+
install
|
14
|
+
rdoc
|
15
|
+
release
|
16
|
+
rerdoc
|
17
|
+
simplecov
|
18
|
+
spec
|
19
|
+
version
|
20
|
+
version:bump:major
|
21
|
+
version:bump:minor
|
22
|
+
version:bump:patch
|
23
|
+
version:write
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 3.0.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.0"
|
12
|
+
gem "juwelier", "~> 2.1.0"
|
13
|
+
gem "simplecov", ">= 0"
|
14
|
+
gem "pry-byebug", "~> 2.0.0", require: false
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Bruno Saibro Silveira
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/brunossilveira/profiler/badges/gpa.svg)](https://codeclimate.com/github/brunossilveira/profiler)
|
2
|
+
|
3
|
+
## brunossilveira-profiler
|
4
|
+
|
5
|
+
This is a gem that reads through a file that contains historical information on phone line bill, divides the data into categories (local calls, long distance calls, SMS and internet) and outputs the consumption.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
`gem install brunossilveira-profiler`
|
10
|
+
|
11
|
+
`profile <file> <phone-number>`
|
12
|
+
|
13
|
+
## Contributing to brunossilveira-profiler
|
14
|
+
|
15
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
16
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
17
|
+
* Fork the project.
|
18
|
+
* Start a feature/bugfix branch.
|
19
|
+
* Commit and push until you are happy with your contribution.
|
20
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
21
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
22
|
+
|
23
|
+
## Copyright
|
24
|
+
|
25
|
+
Copyright (c) 2016 Bruno Saibro Silveira. See LICENSE.txt for
|
26
|
+
further details.
|
27
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'juwelier'
|
15
|
+
Juwelier::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "brunossilveira-profiler"
|
18
|
+
gem.homepage = "http://github.com/brunossilveira/profiler"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Report of phone line consumption}
|
21
|
+
gem.description = %Q{Analyses file, extracts consumption information on calls, internet usage and SMS}
|
22
|
+
gem.email = "djbrunosilveira@gmail.com"
|
23
|
+
gem.authors = ["Bruno Saibro Silveira"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Juwelier::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Code coverage detail"
|
35
|
+
task :simplecov do
|
36
|
+
ENV['COVERAGE'] = "true"
|
37
|
+
Rake::Task['spec'].execute
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "brunossilveira-profiler #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/profiler
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by juwelier
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: brunossilveira-profiler 1.0.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "brunossilveira-profiler"
|
9
|
+
s.version = "1.0.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Bruno Saibro Silveira"]
|
14
|
+
s.date = "2016-07-01"
|
15
|
+
s.description = "Analyses file, extracts consumption information on calls, internet usage and SMS"
|
16
|
+
s.email = "djbrunosilveira@gmail.com"
|
17
|
+
s.executables = ["profiler"]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.md"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".document",
|
24
|
+
".rake_tasks",
|
25
|
+
".rspec",
|
26
|
+
"Gemfile",
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.md",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"bin/profiler",
|
32
|
+
"brunossilveira-profiler.gemspec",
|
33
|
+
"lib/brunossilveira-profiler.rb",
|
34
|
+
"lib/models/row.rb",
|
35
|
+
"lib/services/profiler_service.rb",
|
36
|
+
"lib/utils/mapper.rb",
|
37
|
+
"lib/utils/messages.rb",
|
38
|
+
"lib/utils/parser.rb",
|
39
|
+
"lib/utils/profiler.rb",
|
40
|
+
"spec/models/row_spec.rb",
|
41
|
+
"spec/services/profiler_service_spec.rb",
|
42
|
+
"spec/spec_helper.rb",
|
43
|
+
"spec/test.csv",
|
44
|
+
"spec/utils/mapper_spec.rb",
|
45
|
+
"spec/utils/parser_spec.rb",
|
46
|
+
"spec/utils/profiler_spec.rb"
|
47
|
+
]
|
48
|
+
s.homepage = "http://github.com/brunossilveira/profiler"
|
49
|
+
s.licenses = ["MIT"]
|
50
|
+
s.rubygems_version = "2.5.1"
|
51
|
+
s.summary = "Report of phone line consumption"
|
52
|
+
|
53
|
+
if s.respond_to? :specification_version then
|
54
|
+
s.specification_version = 4
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.0.0"])
|
58
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
60
|
+
s.add_development_dependency(%q<juwelier>, ["~> 2.1.0"])
|
61
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<pry-byebug>, ["~> 2.0.0"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 3.0.0"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
67
|
+
s.add_dependency(%q<juwelier>, ["~> 2.1.0"])
|
68
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
|
+
s.add_dependency(%q<pry-byebug>, ["~> 2.0.0"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 3.0.0"])
|
73
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
75
|
+
s.add_dependency(%q<juwelier>, ["~> 2.1.0"])
|
76
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
77
|
+
s.add_dependency(%q<pry-byebug>, ["~> 2.0.0"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Models
|
2
|
+
require 'models/row'
|
3
|
+
|
4
|
+
# Utils
|
5
|
+
require 'utils/mapper'
|
6
|
+
require 'utils/messages'
|
7
|
+
require 'utils/parser'
|
8
|
+
require 'utils/profiler'
|
9
|
+
|
10
|
+
# Services
|
11
|
+
require 'services/profiler_service'
|
12
|
+
|
13
|
+
module Brunossilveira
|
14
|
+
class Profiler
|
15
|
+
def self.run!(*args)
|
16
|
+
ProfilerService.new(*args).call
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/models/row.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
class Row
|
4
|
+
attr_accessor :total
|
5
|
+
attr_reader :data, :type
|
6
|
+
|
7
|
+
def initialize(data, type)
|
8
|
+
@data = data.to_s.split('m').map { |v| v.sub(/\D+/, '') } || []
|
9
|
+
@type = type
|
10
|
+
|
11
|
+
convert
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def convert
|
17
|
+
if data.size == 2
|
18
|
+
@total = convert_time(data.first, data.last)
|
19
|
+
elsif data.size == 1
|
20
|
+
@total = convert_bytes(data.first)
|
21
|
+
else
|
22
|
+
@total = 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def convert_bytes(value)
|
27
|
+
value.gsub(',', '.').to_f
|
28
|
+
end
|
29
|
+
|
30
|
+
def convert_time(minutes, seconds)
|
31
|
+
time = Time.parse("00:#{minutes}:#{seconds}")
|
32
|
+
|
33
|
+
time.to_i - beginning.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def beginning
|
37
|
+
Time.parse('00:00')
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
class ProfilerService
|
4
|
+
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize(*args)
|
8
|
+
@options = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
parsed_options = Parser.new(options).parse!
|
13
|
+
result = Mapper.new(parsed_options[:file_name], parsed_options[:phone_number]).map
|
14
|
+
|
15
|
+
profiler = Profiler.new(result)
|
16
|
+
profiler.process
|
17
|
+
|
18
|
+
printf "Informações para o número #{parsed_options[:phone_number]}\n"
|
19
|
+
printf "SMS: #{profiler.sms}\n"
|
20
|
+
printf "Internet: #{profiler.internet * 1000} bytes\n"
|
21
|
+
printf "Chamadas Locais:\n"
|
22
|
+
printf " Celular: #{profiler.locals[:cellphone]}\n"
|
23
|
+
printf " Telefone Fixo: #{profiler.locals[:landline]}\n"
|
24
|
+
printf "Chamadas Longa Distância:\n"
|
25
|
+
printf " Celular: #{profiler.long_distance[:cellphone]}\n"
|
26
|
+
printf " Telefone Fixo: #{profiler.long_distance[:landline]}\n"
|
27
|
+
end
|
28
|
+
end
|
data/lib/utils/mapper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
class Mapper
|
4
|
+
attr_reader :file_name, :phone_number
|
5
|
+
|
6
|
+
def initialize(file_name, phone_number)
|
7
|
+
@file_name = file_name
|
8
|
+
@phone_number = phone_number
|
9
|
+
|
10
|
+
raise 'File not found' unless File.exists?(file_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def map
|
14
|
+
result = {
|
15
|
+
locals: [],
|
16
|
+
long_distance: [],
|
17
|
+
sms: [],
|
18
|
+
internet: []
|
19
|
+
}
|
20
|
+
|
21
|
+
CSV.foreach(file_name, { headers: :first_row, col_sep: ';' }) do |csv|
|
22
|
+
row = csv.to_hash
|
23
|
+
service = row['Tpserv']
|
24
|
+
|
25
|
+
if row['NumAcs'] == phone_number
|
26
|
+
types.keys.each do |key|
|
27
|
+
result[key] << Row.new(row['Duração'], row['Destino']) if row['Tpserv'].include? types[key]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def types
|
38
|
+
{
|
39
|
+
locals: 'Chamadas Locais',
|
40
|
+
long_distance: 'Chamadas Longa Distância',
|
41
|
+
sms: 'TIM Torpedo',
|
42
|
+
internet: 'TIM Wap Fast'
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class Messages
|
2
|
+
NO_ARGUMENT_ERROR = 'Usage: profiler <file> <phone_number>'
|
3
|
+
WRONG_NUMBER_OF_ARGUMENTS_ERROR = "Wrong number of arguments\n#{NO_ARGUMENT_ERROR}"
|
4
|
+
WRONG_FILE_FORMAT_ERROR = 'Filename must be <name>.<extension>'
|
5
|
+
WRONG_NUMBER_FORMAT_ERROR = 'Phone number must be XXX-XXXX-XXXX'
|
6
|
+
end
|
data/lib/utils/parser.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
class Parser
|
2
|
+
attr_reader :options
|
3
|
+
|
4
|
+
FILE_FORMAT = /.+[.].+/
|
5
|
+
NUMBER_FORMAT = /(\d{3})-(\d{4})-(\d{4})/
|
6
|
+
|
7
|
+
def initialize(args)
|
8
|
+
@options = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse!
|
12
|
+
abort Messages::NO_ARGUMENT_ERROR if options.empty?
|
13
|
+
abort Messages::WRONG_NUMBER_OF_ARGUMENTS_ERROR if options.count > 2
|
14
|
+
abort Messages::WRONG_FILE_FORMAT_ERROR unless file_format_correct?
|
15
|
+
abort Messages::WRONG_NUMBER_FORMAT_ERROR unless number_format_correct?
|
16
|
+
|
17
|
+
{ file_name: options.first, phone_number: options.last }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def file_format_correct?
|
23
|
+
options.first =~ FILE_FORMAT
|
24
|
+
end
|
25
|
+
|
26
|
+
def number_format_correct?
|
27
|
+
options.last =~ NUMBER_FORMAT
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class Profiler
|
2
|
+
attr_accessor :sms, :internet, :locals, :long_distance
|
3
|
+
attr_reader :data
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@data = data
|
7
|
+
@sms, @internet = nil
|
8
|
+
@locals = { cellphone: 0, landline: 0 }
|
9
|
+
@long_distance = { cellphone: 0, landline: 0 }
|
10
|
+
end
|
11
|
+
|
12
|
+
def process
|
13
|
+
process_sms
|
14
|
+
process_internet
|
15
|
+
process_locals
|
16
|
+
process_long_distance
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def process_sms
|
24
|
+
@sms = data[:sms].count
|
25
|
+
end
|
26
|
+
|
27
|
+
def process_internet
|
28
|
+
sum = 0
|
29
|
+
|
30
|
+
data[:internet].each do |row|
|
31
|
+
sum = sum + row.total
|
32
|
+
end
|
33
|
+
|
34
|
+
@internet = sum
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_locals
|
38
|
+
cellphone = 0
|
39
|
+
landline = 0
|
40
|
+
|
41
|
+
data[:locals].each do |row|
|
42
|
+
if row.type.include? 'MOVEL'
|
43
|
+
cellphone = cellphone + row.total
|
44
|
+
else
|
45
|
+
landline = landline + row.total
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
locals[:cellphone] = convert_sum(cellphone)
|
50
|
+
locals[:landline] = convert_sum(landline)
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_long_distance
|
54
|
+
cellphone = 0
|
55
|
+
landline = 0
|
56
|
+
|
57
|
+
data[:long_distance].each do |row|
|
58
|
+
if row.type.include? 'MOVEL'
|
59
|
+
cellphone = cellphone + row.total
|
60
|
+
else
|
61
|
+
landline = landline + row.total
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
long_distance[:cellphone] = convert_sum(cellphone)
|
66
|
+
long_distance[:landline] = convert_sum(landline)
|
67
|
+
end
|
68
|
+
|
69
|
+
def convert_sum(sum)
|
70
|
+
Time.at(sum).utc.strftime("%H:%M:%S")
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Row do
|
4
|
+
describe '.initialize' do
|
5
|
+
subject { described_class.new(value, nil) }
|
6
|
+
|
7
|
+
context 'when value is valid' do
|
8
|
+
let(:value) { '10m60s' }
|
9
|
+
|
10
|
+
it 'initializes object correctly' do
|
11
|
+
expect(subject.total).to eq 660
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when value is kb format' do
|
15
|
+
let(:value) { '10jxxx' }
|
16
|
+
|
17
|
+
it 'initializes object correctly' do
|
18
|
+
expect(subject.total).to eq 10
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when value is nil' do
|
24
|
+
let(:value) { nil }
|
25
|
+
|
26
|
+
it 'initializes object correctly' do
|
27
|
+
expect(subject.total).to eq 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when value is empty string' do
|
32
|
+
let(:value) { '' }
|
33
|
+
|
34
|
+
it 'initializes object correctly' do
|
35
|
+
expect(subject.total).to eq 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
require 'brunossilveira-profiler'
|
22
|
+
|
23
|
+
# Requires supporting files with custom matchers and macros, etc,
|
24
|
+
# in ./support/ and its subdirectories.
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
|
29
|
+
end
|
data/spec/test.csv
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mapper do
|
4
|
+
describe '.map' do
|
5
|
+
subject { described_class.new(filename, '0').map }
|
6
|
+
|
7
|
+
context 'when non existing file is provided' do
|
8
|
+
let(:filename) { 'invalid' }
|
9
|
+
|
10
|
+
it 'raises error' do
|
11
|
+
expect { subject }.to raise_error(RuntimeError, 'File not found')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when existing file is provided' do
|
16
|
+
let(:filename) { File.join(Dir.pwd, 'spec', 'test.csv') }
|
17
|
+
|
18
|
+
it 'maps correctly' do
|
19
|
+
result = subject
|
20
|
+
|
21
|
+
expect(result[:locals].count).to eq 5
|
22
|
+
expect(result[:long_distance].count).to eq 0
|
23
|
+
expect(result[:sms].count).to eq 0
|
24
|
+
expect(result[:internet].count).to eq 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Parser do
|
4
|
+
describe '#parse!' do
|
5
|
+
subject { described_class.new(options).parse! }
|
6
|
+
|
7
|
+
context 'when options is empty' do
|
8
|
+
let(:options) { [] }
|
9
|
+
|
10
|
+
it 'returns no arguments error message' do
|
11
|
+
expect { subject }.to raise_error SystemExit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when options are incomplete' do
|
16
|
+
let(:options) { ['file.extension'] }
|
17
|
+
|
18
|
+
it 'returns no arguments error message' do
|
19
|
+
expect { subject }.to raise_error SystemExit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when options are invalid' do
|
24
|
+
let(:options) { ['invalid_file', 'invalid_number'] }
|
25
|
+
|
26
|
+
it 'returns no arguments error message' do
|
27
|
+
expect { subject }.to raise_error SystemExit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when options are valid' do
|
32
|
+
let(:options) { ['file.extension', '000-0000-0000'] }
|
33
|
+
let(:result) { { file_name: options.first, phone_number: options.last } }
|
34
|
+
|
35
|
+
it 'returns no arguments error message' do
|
36
|
+
expect(subject).to eq result
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Profiler do
|
4
|
+
describe '.process' do
|
5
|
+
context 'when processing data' do
|
6
|
+
let(:locals_rows) do
|
7
|
+
[
|
8
|
+
Row.new('00m10s', 'MOVEL'),
|
9
|
+
Row.new('00m10s', 'MOVEL'),
|
10
|
+
Row.new('00m10s', 'MOVEL'),
|
11
|
+
Row.new('00m10s', 'MOVEL')
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:long_distance_rows) do
|
16
|
+
[
|
17
|
+
Row.new('00m10s', 'MOVEL'),
|
18
|
+
Row.new('00m10s', 'MOVEL'),
|
19
|
+
Row.new('00m10s', 'MOVEL'),
|
20
|
+
Row.new('00m10s', 'MOVEL')
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:sms_rows) do
|
25
|
+
[
|
26
|
+
Row.new('', ''),
|
27
|
+
Row.new('', ''),
|
28
|
+
Row.new('', ''),
|
29
|
+
Row.new('', '')
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:internet_rows) do
|
34
|
+
[
|
35
|
+
Row.new('10 KB', ''),
|
36
|
+
Row.new('10 KB', ''),
|
37
|
+
Row.new('10 KB', ''),
|
38
|
+
Row.new('10 KB', '')
|
39
|
+
]
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:data) do
|
43
|
+
{
|
44
|
+
locals: locals_rows,
|
45
|
+
long_distance: long_distance_rows,
|
46
|
+
sms: sms_rows,
|
47
|
+
internet: internet_rows
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
subject { described_class.new(data).process }
|
52
|
+
|
53
|
+
it 'calculates all values correctly' do
|
54
|
+
expect(subject.sms).to eq(4)
|
55
|
+
expect(subject.internet).to eq(40)
|
56
|
+
expect(subject.locals[:cellphone]).to eq('00:00:40')
|
57
|
+
expect(subject.long_distance[:cellphone]).to eq('00:00:40')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brunossilveira-profiler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Saibro Silveira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: juwelier
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.0
|
97
|
+
description: Analyses file, extracts consumption information on calls, internet usage
|
98
|
+
and SMS
|
99
|
+
email: djbrunosilveira@gmail.com
|
100
|
+
executables:
|
101
|
+
- profiler
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
files:
|
107
|
+
- ".document"
|
108
|
+
- ".rake_tasks"
|
109
|
+
- ".rspec"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- VERSION
|
115
|
+
- bin/profiler
|
116
|
+
- brunossilveira-profiler.gemspec
|
117
|
+
- lib/brunossilveira-profiler.rb
|
118
|
+
- lib/models/row.rb
|
119
|
+
- lib/services/profiler_service.rb
|
120
|
+
- lib/utils/mapper.rb
|
121
|
+
- lib/utils/messages.rb
|
122
|
+
- lib/utils/parser.rb
|
123
|
+
- lib/utils/profiler.rb
|
124
|
+
- spec/models/row_spec.rb
|
125
|
+
- spec/services/profiler_service_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/test.csv
|
128
|
+
- spec/utils/mapper_spec.rb
|
129
|
+
- spec/utils/parser_spec.rb
|
130
|
+
- spec/utils/profiler_spec.rb
|
131
|
+
homepage: http://github.com/brunossilveira/profiler
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.5.1
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Report of phone line consumption
|
155
|
+
test_files: []
|