Skip to content

Commit

Permalink
Merge pull request #14 from ninoseki/add-refang-support
Browse files Browse the repository at this point in the history
feat: add defanged IP support
  • Loading branch information
ninoseki committed Sep 28, 2019
2 parents af907ed + 328a8c7 commit 15e810f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ $ kokki japan
🇯🇵
$ kokki 202.214.194.147
🇯🇵
# it suports a defanged ip as an input
$ kokki 1.1.1[.]1
🇦🇺
$ kokki "1.1.1(.)1"
🇦🇺
```

### As a library
Expand Down
6 changes: 5 additions & 1 deletion lib/kokki/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ def self.convert(input)

private

def refang(input)
input.gsub("[.]", ".").gsub("(.)", ".")
end

def convert_as_ip_address(ip_address)
ip = IPAddress.new(ip_address)
ip = IPAddress.new(refang(ip_address))
dict.lookup_by_alpha_2_code ip.country_code
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
end
end

context "when given a defanged ip address" do
it do
flag = subject.convert("1[.]0[.]16[.]0")
expect(flag).to eq("🇯🇵")
end
end

context "when given an invalid input" do
it "raises an InvalidError" do
expect { subject.convert("test") }.to raise_error(Kokki::InvalidInputError)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 15e810f

Please sign in to comment.