-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ran rubocop on the code (with autofix) - refactored test setup - refactored code (e.g. request libraries) - added test coverage for the library code
- Loading branch information
Showing
21 changed files
with
294 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
require "bundler/gem_tasks" | ||
require "minitest/autorun" | ||
require "simplecov" | ||
require "simplecov-lcov" | ||
# frozen_string_literal: true | ||
|
||
require 'bundler/gem_tasks' | ||
require 'rake/testtask' | ||
|
||
Encoding.default_external = Encoding::UTF_8 | ||
Encoding.default_internal = Encoding::UTF_8 | ||
|
||
task :test do | ||
Rake::TestTask.new do |t| | ||
ENV['COVERAGE'] = 'true' | ||
t.pattern = 'tests/*_test.rb' | ||
|
||
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter | ||
SimpleCov::Formatter::LcovFormatter.config do |c| | ||
c.output_directory = './coverage' | ||
c.report_with_single_file = true | ||
c.single_report_path = './coverage/lcov.info' | ||
end | ||
SimpleCov.start | ||
|
||
$LOAD_PATH.unshift('lib', 'tests') | ||
Dir.glob('./tests/*_test.rb') do |f| | ||
require f | ||
end | ||
# $LOAD_PATH.unshift('lib', 'tests') | ||
# Dir.glob('./tests/*_test.rb').sort.each do |f| | ||
# require f | ||
# end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module Apt | ||
module Spy2 | ||
# lookup a country based on code | ||
class Country | ||
|
||
def initialize(country_database) | ||
@database = country_database | ||
end | ||
|
||
def to_country_name(code) | ||
code = code.upcase | ||
return capitalize(code) unless code.length == 2 | ||
return capitalize!(code) unless code.length == 2 | ||
|
||
File.open(@database).each do |line| | ||
country, tld = line.split(';', 2) | ||
tld.gsub!(/\n/, '') | ||
|
||
if code == tld | ||
return capitalize(country) | ||
end | ||
|
||
return capitalize!(country) if code == tld | ||
end | ||
|
||
raise "Could not look up: #{code}" | ||
end | ||
|
||
private | ||
def capitalize(str) | ||
return str.split(" ").map(&:capitalize).join(" ") | ||
end | ||
|
||
def capitalize!(str) | ||
str.split(' ').map(&:capitalize).join(' ') | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.