trackler 2.1.0.23 → 2.1.0.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/tracks/ceylon/LICENSE +2 -2
- data/tracks/ceylon/README.md +0 -5
- data/tracks/ecmascript/.editorconfig +7 -0
- data/tracks/ecmascript/Makefile +8 -0
- data/tracks/ecmascript/bin/md5-hash +21 -0
- data/tracks/ecmascript/exercises/connect/package.json +3 -3
- data/tracks/elixir/exercises/atbash-cipher/{atbash.exs → atbash_cipher.exs} +4 -0
- data/tracks/elixir/exercises/atbash-cipher/atbash_cipher_test.exs +29 -1
- data/tracks/elixir/exercises/atbash-cipher/example.exs +12 -6
- data/tracks/elixir/exercises/phone-number/example.exs +71 -29
- data/tracks/elixir/exercises/phone-number/phone_number.exs +22 -10
- data/tracks/elixir/exercises/phone-number/phone_number_test.exs +37 -12
- data/tracks/elm/.github/stale.yml +0 -0
- data/tracks/elm/.gitignore +1 -0
- data/tracks/elm/.travis.yml +20 -1
- data/tracks/elm/README.md +9 -20
- data/tracks/elm/bin/build.sh +15 -18
- data/tracks/elm/bin/install-elm-format +1 -1
- data/tracks/elm/config.json +172 -167
- data/tracks/elm/exercises/accumulate/elm-package.json +1 -3
- data/tracks/elm/exercises/accumulate/package.json +3 -3
- data/tracks/elm/exercises/accumulate/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/accumulate/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/allergies/elm-package.json +2 -3
- data/tracks/elm/exercises/allergies/package.json +3 -3
- data/tracks/elm/exercises/allergies/{Tests.elm → tests/Tests.elm} +2 -12
- data/tracks/elm/exercises/allergies/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/anagram/elm-package.json +2 -3
- data/tracks/elm/exercises/anagram/package.json +3 -3
- data/tracks/elm/exercises/anagram/{Tests.elm → tests/Tests.elm} +4 -14
- data/tracks/elm/exercises/anagram/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/atbash-cipher/elm-package.json +2 -3
- data/tracks/elm/exercises/atbash-cipher/package.json +3 -3
- data/tracks/elm/exercises/atbash-cipher/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/atbash-cipher/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/bob/elm-package.json +2 -3
- data/tracks/elm/exercises/bob/package.json +3 -3
- data/tracks/elm/exercises/bob/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/bob/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/difference-of-squares/elm-package.json +2 -3
- data/tracks/elm/exercises/difference-of-squares/package.json +3 -3
- data/tracks/elm/exercises/difference-of-squares/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/difference-of-squares/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/gigasecond/elm-package.json +2 -3
- data/tracks/elm/exercises/gigasecond/package.json +3 -3
- data/tracks/elm/exercises/gigasecond/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/gigasecond/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/grade-school/elm-package.json +2 -3
- data/tracks/elm/exercises/grade-school/package.json +3 -3
- data/tracks/elm/exercises/grade-school/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/grade-school/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/grains/Grains.elm +2 -0
- data/tracks/elm/exercises/grains/Grains.example.elm +9 -0
- data/tracks/elm/exercises/grains/elm-package.json +14 -0
- data/tracks/elm/exercises/grains/package.json +13 -0
- data/tracks/elm/exercises/grains/tests/Tests.elm +38 -0
- data/tracks/elm/exercises/grains/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/hamming/elm-package.json +2 -3
- data/tracks/elm/exercises/hamming/package.json +3 -3
- data/tracks/elm/exercises/hamming/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/hamming/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/hello-world/elm-package.json +2 -3
- data/tracks/elm/exercises/hello-world/package.json +3 -3
- data/tracks/elm/exercises/hello-world/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/hello-world/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/largest-series-product/elm-package.json +2 -3
- data/tracks/elm/exercises/largest-series-product/package.json +3 -3
- data/tracks/elm/exercises/largest-series-product/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/largest-series-product/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/leap/elm-package.json +2 -3
- data/tracks/elm/exercises/leap/package.json +3 -3
- data/tracks/elm/exercises/leap/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/leap/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/list-ops/elm-package.json +2 -3
- data/tracks/elm/exercises/list-ops/package.json +3 -3
- data/tracks/elm/exercises/list-ops/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/list-ops/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/nucleotide-count/elm-package.json +2 -3
- data/tracks/elm/exercises/nucleotide-count/package.json +3 -3
- data/tracks/elm/exercises/nucleotide-count/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/nucleotide-count/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/pangram/elm-package.json +2 -3
- data/tracks/elm/exercises/pangram/package.json +3 -3
- data/tracks/elm/exercises/pangram/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/pangram/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/phone-number/elm-package.json +2 -3
- data/tracks/elm/exercises/phone-number/package.json +3 -3
- data/tracks/elm/exercises/phone-number/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/phone-number/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/raindrops/elm-package.json +2 -3
- data/tracks/elm/exercises/raindrops/package.json +3 -3
- data/tracks/elm/exercises/raindrops/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/raindrops/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/rna-transcription/elm-package.json +2 -3
- data/tracks/elm/exercises/rna-transcription/package.json +3 -3
- data/tracks/elm/exercises/rna-transcription/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/rna-transcription/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/robot-simulator/elm-package.json +2 -3
- data/tracks/elm/exercises/robot-simulator/package.json +3 -3
- data/tracks/elm/exercises/robot-simulator/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/robot-simulator/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/roman-numerals/elm-package.json +2 -3
- data/tracks/elm/exercises/roman-numerals/package.json +3 -3
- data/tracks/elm/exercises/roman-numerals/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/roman-numerals/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/run-length-encoding/elm-package.json +2 -3
- data/tracks/elm/exercises/run-length-encoding/package.json +3 -3
- data/tracks/elm/exercises/run-length-encoding/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/run-length-encoding/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/say/elm-package.json +2 -3
- data/tracks/elm/exercises/say/package.json +3 -3
- data/tracks/elm/exercises/say/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/say/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/scrabble-score/elm-package.json +2 -3
- data/tracks/elm/exercises/scrabble-score/package.json +3 -3
- data/tracks/elm/exercises/scrabble-score/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/scrabble-score/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/series/elm-package.json +2 -3
- data/tracks/elm/exercises/series/package.json +3 -3
- data/tracks/elm/exercises/series/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/series/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/space-age/elm-package.json +2 -3
- data/tracks/elm/exercises/space-age/package.json +3 -3
- data/tracks/elm/exercises/space-age/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/space-age/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/strain/elm-package.json +2 -3
- data/tracks/elm/exercises/strain/package.json +3 -3
- data/tracks/elm/exercises/strain/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/strain/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/sublist/elm-package.json +2 -3
- data/tracks/elm/exercises/sublist/package.json +3 -3
- data/tracks/elm/exercises/sublist/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/sublist/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/sum-of-multiples/elm-package.json +2 -3
- data/tracks/elm/exercises/sum-of-multiples/package.json +3 -3
- data/tracks/elm/exercises/sum-of-multiples/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/sum-of-multiples/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/triangle/elm-package.json +2 -3
- data/tracks/elm/exercises/triangle/package.json +3 -3
- data/tracks/elm/exercises/triangle/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/triangle/tests/elm-package.json +16 -0
- data/tracks/elm/exercises/word-count/elm-package.json +2 -3
- data/tracks/elm/exercises/word-count/package.json +3 -3
- data/tracks/elm/exercises/word-count/{Tests.elm → tests/Tests.elm} +1 -11
- data/tracks/elm/exercises/word-count/tests/elm-package.json +16 -0
- data/tracks/elm/package.json +2 -2
- data/tracks/java/exercises/clock/HINT.md +3 -0
- data/tracks/java/exercises/clock/src/test/java/ClockAddTest.java +3 -0
- data/tracks/java/exercises/clock/src/test/java/ClockCreationTest.java +3 -0
- data/tracks/java/exercises/clock/src/test/java/ClockEqualTest.java +21 -17
- data/tracks/java/exercises/simple-linked-list/src/example/java/SimpleLinkedList.java +13 -13
- data/tracks/java/exercises/sublist/src/example/java/RelationshipComputer.java +1 -1
- data/tracks/java/exercises/sublist/src/main/java/RelationshipComputer.java +1 -1
- data/tracks/perl5/docs/TESTS.md +2 -2
- data/tracks/ruby/LICENSE +2 -2
- data/tracks/ruby/README.md +0 -5
- data/tracks/typescript/LICENSE +2 -2
- data/tracks/typescript/README.md +0 -5
- data/tracks/vimscript/README.md +1 -0
- data/tracks/vimscript/TRACK_HINTS.md +26 -1
- data/tracks/vimscript/config.json +15 -0
- data/tracks/vimscript/docs/ABOUT.md +1 -1
- data/tracks/vimscript/exercises/nucleotide-count/example.vim +18 -0
- data/tracks/vimscript/exercises/nucleotide-count/nucleotide_count.vader +38 -0
- data/tracks/vimscript/exercises/nucleotide-count/nucleotide_count.vim +16 -0
- data/tracks/vimscript/exercises/phone-number/example.vim +4 -0
- data/tracks/vimscript/exercises/phone-number/phone_number.vader +36 -0
- data/tracks/vimscript/exercises/phone-number/phone_number.vim +11 -0
- data/tracks/vimscript/exercises/roman-numerals/example.vim +29 -0
- data/tracks/vimscript/exercises/roman-numerals/roman_numerals.vader +53 -0
- data/tracks/vimscript/exercises/roman-numerals/roman_numerals.vim +14 -0
- metadata +81 -35
- data/tracks/elm/elm-package.json +0 -46
- data/tracks/elm/exercises/hello-world/yarn.lock +0 -1136
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f709e319865d19a3edd18d5e20ff5f0fabcd438b
|
4
|
+
data.tar.gz: 9a9e667cc9ef535f6cb3fd28270f4a09f8a4acf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae5e1c6d35bcbe9879f021fe2130ecfa6cf7a365e40d56271c7b04d66fc367fa80c768ebfb8d466a8ef6208a1e26bbd5cc2a9e0a61d6d8763cd945392afd7ed7
|
7
|
+
data.tar.gz: 946c99dd215e5e1f0d74089a72280e33e7ce035743381878fd8f363c960e63685a1e52ed2307a94098fbb1f047229e127030bd97783e6e09d6235f64d0319218
|
data/lib/trackler/version.rb
CHANGED
data/tracks/ceylon/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
MIT License
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2017 Exercism, Inc
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/tracks/ceylon/README.md
CHANGED
@@ -149,11 +149,6 @@ The Travis CI run would need to uncomment the cases as well (without uncommentin
|
|
149
149
|
|
150
150
|
The current maintainer does not have a good solution to this, so ideas here are welcome.
|
151
151
|
|
152
|
-
## License
|
153
|
-
|
154
|
-
The MIT License (MIT)
|
155
|
-
|
156
|
-
Copyright (c) 2016 Katrina Owen, _@kytrinyx.com
|
157
152
|
|
158
153
|
### Ceylon icon
|
159
154
|
The Ceylon icon is assumed to be owned by Red Hat, Inc. It appears to be released under the [Creative Commons Attribution Share-Alike 3.0 license](https://creativecommons.org/licenses/by-sa/3.0/). We have modified its colour scheme for use on Exercism.
|
@@ -17,6 +17,13 @@ trim_trailing_whitespace = true
|
|
17
17
|
indent_style = space
|
18
18
|
indent_size = 2
|
19
19
|
|
20
|
+
###########################################################
|
21
|
+
; bash
|
22
|
+
###########################################################
|
23
|
+
|
24
|
+
[{bin/*,*.sh}]
|
25
|
+
indent_size = 4
|
26
|
+
|
20
27
|
###########################################################
|
21
28
|
; make
|
22
29
|
###########################################################
|
data/tracks/ecmascript/Makefile
CHANGED
@@ -11,6 +11,13 @@ FILEEXT := "js"
|
|
11
11
|
EXAMPLE := "example.$(FILEEXT)"
|
12
12
|
TSTFILE := "$(subst _,-,$(ASSIGNMENT)).spec.$(FILEEXT)"
|
13
13
|
|
14
|
+
# package.json MD5 hash
|
15
|
+
SOURCE_PKG_MD5 ?= "`./bin/md5-hash ./package.json`"
|
16
|
+
PKG_FILES= $(shell find ./exercises/*/* -name package.json)
|
17
|
+
|
18
|
+
test-package-files:
|
19
|
+
@for pkg in $(PKG_FILES); do ! ./bin/md5-hash $$pkg | grep -qv $(SOURCE_PKG_MD5) || exit 1; done
|
20
|
+
|
14
21
|
test-assignment:
|
15
22
|
@cp package.json exercises/$(ASSIGNMENT)
|
16
23
|
@echo "running tests for: $(ASSIGNMENT)"
|
@@ -24,4 +31,5 @@ test-assignment:
|
|
24
31
|
@rmdir $(OUTDIR)
|
25
32
|
|
26
33
|
test:
|
34
|
+
@$(MAKE) -s test-package-files
|
27
35
|
@for assignment in $(ASSIGNMENTS); do ASSIGNMENT=$$assignment $(MAKE) -s test-assignment || exit 1; done
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Calculates the MD5 hash of a given file. It uses hashing utilities powered by
|
4
|
+
# operating systems, but wraps them into a consistent interface.
|
5
|
+
|
6
|
+
OS=$(
|
7
|
+
case $(uname) in
|
8
|
+
(Darwin*) echo "mac";;
|
9
|
+
(Linux*) echo "linux";;
|
10
|
+
# TODO: implement MD5 hashing on Windows
|
11
|
+
# (Windows*) echo "windows";;
|
12
|
+
(*) echo "linux";;
|
13
|
+
esac
|
14
|
+
)
|
15
|
+
|
16
|
+
case $OS in
|
17
|
+
mac )
|
18
|
+
md5 -q $@;;
|
19
|
+
linux )
|
20
|
+
md5sum $@ | sed -E 's/([a-z0-9]{32}).+$/\1/';;
|
21
|
+
esac
|
@@ -9,10 +9,10 @@
|
|
9
9
|
"url": "https://github.com/exercism/xecmascript"
|
10
10
|
},
|
11
11
|
"devDependencies": {
|
12
|
-
"babel-jest": "^
|
13
|
-
"babel-preset-env": "^1.
|
12
|
+
"babel-jest": "^20.0.1",
|
13
|
+
"babel-preset-env": "^1.4.0",
|
14
14
|
"eslint": "^3.19.0",
|
15
|
-
"jest": "^
|
15
|
+
"jest": "^20.0.1"
|
16
16
|
},
|
17
17
|
"jest": {
|
18
18
|
"modulePathIgnorePatterns": [
|
@@ -1,5 +1,5 @@
|
|
1
1
|
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
|
2
|
-
Code.load_file("
|
2
|
+
Code.load_file("atbash_cipher.exs", __DIR__)
|
3
3
|
end
|
4
4
|
|
5
5
|
ExUnit.start
|
@@ -49,4 +49,32 @@ defmodule AtbashTest do
|
|
49
49
|
cipher = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
|
50
50
|
assert Atbash.encode(plaintext) == cipher
|
51
51
|
end
|
52
|
+
|
53
|
+
@tag :pending
|
54
|
+
test "decode exercism" do
|
55
|
+
cipher = "vcvix rhn"
|
56
|
+
plaintext = "exercism"
|
57
|
+
assert Atbash.decode(cipher) == plaintext
|
58
|
+
end
|
59
|
+
|
60
|
+
@tag :pending
|
61
|
+
test "decode a sentence" do
|
62
|
+
cipher = "zmlyh gzxov rhlug vmzhg vkkrm thglm v"
|
63
|
+
plaintext = "anobstacleisoftenasteppingstone"
|
64
|
+
assert Atbash.decode(cipher) == plaintext
|
65
|
+
end
|
66
|
+
|
67
|
+
@tag :pending
|
68
|
+
test "decode numbers" do
|
69
|
+
cipher = "gvhgr mt123 gvhgr mt"
|
70
|
+
plaintext = "testing123testing"
|
71
|
+
assert Atbash.decode(cipher) == plaintext
|
72
|
+
end
|
73
|
+
|
74
|
+
@tag :pending
|
75
|
+
test "decode all the letters" do
|
76
|
+
cipher = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
|
77
|
+
plaintext = "thequickbrownfoxjumpsoverthelazydog"
|
78
|
+
assert Atbash.decode(cipher) == plaintext
|
79
|
+
end
|
52
80
|
end
|
@@ -9,19 +9,25 @@ defmodule Atbash do
|
|
9
9
|
iex> Atbash.encode("completely insecure")
|
10
10
|
"xlnko vgvob rmhvx fiv"
|
11
11
|
"""
|
12
|
+
@spec encode(String.t) :: String.t
|
12
13
|
def encode(plaintext) do
|
13
|
-
plaintext |> normalize |>
|
14
|
+
plaintext |> normalize |> transpose |> chunk |> Enum.join(" ")
|
15
|
+
end
|
16
|
+
|
17
|
+
@spec decode(String.t) :: String.t
|
18
|
+
def decode(cipher) do
|
19
|
+
cipher |> normalize |> transpose
|
14
20
|
end
|
15
21
|
|
16
22
|
defp normalize(input) do
|
17
23
|
Regex.replace(~r{\W}, String.downcase(input), "")
|
18
24
|
end
|
19
25
|
|
20
|
-
defp
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
defp transpose(text) do
|
27
|
+
text
|
28
|
+
|> String.to_char_list
|
29
|
+
|> Enum.map(&convert/1)
|
30
|
+
|> List.to_string
|
25
31
|
end
|
26
32
|
|
27
33
|
defp convert(character) do
|
@@ -2,55 +2,97 @@ defmodule Phone do
|
|
2
2
|
@moduledoc """
|
3
3
|
Utilities to work with phone numbers.
|
4
4
|
"""
|
5
|
+
@invalid "0000000000"
|
5
6
|
|
6
7
|
@doc """
|
7
|
-
|
8
|
+
Remove formatting from a phone number.
|
8
9
|
|
9
|
-
Returns 0000000000 if
|
10
|
+
Returns "0000000000" if phone number is not valid
|
11
|
+
(10 digits or "1" followed by 10 digits)
|
12
|
+
|
13
|
+
## Examples
|
14
|
+
|
15
|
+
iex> Phone.number("212-555-0100")
|
16
|
+
"2125550100"
|
17
|
+
|
18
|
+
iex> Phone.number("+1 (212) 555-0100")
|
19
|
+
"2125550100"
|
20
|
+
|
21
|
+
iex> Phone.number("+1 (212) 055-0100")
|
22
|
+
"0000000000"
|
23
|
+
|
24
|
+
iex> Phone.number("(212) 555-0100")
|
25
|
+
"2125550100"
|
26
|
+
|
27
|
+
iex> Phone.number("867.5309")
|
28
|
+
"0000000000"
|
10
29
|
"""
|
11
30
|
@spec number(String.t) :: String.t
|
12
31
|
def number(raw) do
|
13
32
|
raw
|
14
|
-
|>
|
15
|
-
|>
|
33
|
+
|> String.replace(~r/[\s+.()-]/, "") # remove decorations
|
34
|
+
|> valid?
|
35
|
+
|> (fn false -> @invalid; num -> String.replace(num, ~r/^1/, "") end).()
|
16
36
|
end
|
17
37
|
|
18
|
-
|
19
|
-
|
20
|
-
|
38
|
+
defp valid?(num) do
|
39
|
+
Regex.match?(~r/^1?(?:[2-9][0-9]{2}){2}\d{4}$/, num)
|
40
|
+
|> (fn true -> num; false -> false end).()
|
21
41
|
end
|
22
42
|
|
23
43
|
@doc """
|
24
|
-
|
44
|
+
Extract the area code from a phone number
|
45
|
+
|
46
|
+
Returns the first three digits from a phone number,
|
47
|
+
ignoring long distance indicator
|
48
|
+
|
49
|
+
## Examples
|
50
|
+
|
51
|
+
iex> Phone.area_code("212-555-0100")
|
52
|
+
"212"
|
53
|
+
|
54
|
+
iex> Phone.area_code("+1 (212) 555-0100")
|
55
|
+
"212"
|
56
|
+
|
57
|
+
iex> Phone.area_code("+1 (012) 555-0100")
|
58
|
+
"000"
|
25
59
|
|
26
|
-
|
60
|
+
iex> Phone.area_code("867.5309")
|
61
|
+
"000"
|
27
62
|
"""
|
28
63
|
@spec area_code(String.t) :: String.t
|
29
|
-
def area_code(
|
30
|
-
|
31
|
-
|>
|
32
|
-
|>
|
64
|
+
def area_code(raw) do
|
65
|
+
raw
|
66
|
+
|> __MODULE__.number
|
67
|
+
|> String.slice(0, 3) # the first three digits are area_code
|
33
68
|
end
|
34
69
|
|
35
|
-
@
|
36
|
-
|
37
|
-
str
|
38
|
-
|> to_parts
|
39
|
-
|> Enum.at(1)
|
40
|
-
end
|
70
|
+
@doc """
|
71
|
+
Pretty print a phone number
|
41
72
|
|
42
|
-
|
43
|
-
|
44
|
-
str
|
45
|
-
|> to_parts
|
46
|
-
|> List.last
|
47
|
-
end
|
73
|
+
Wraps the area code in parentheses and separates
|
74
|
+
exchange and subscriber number with a dash.
|
48
75
|
|
49
|
-
|
50
|
-
|
76
|
+
## Examples
|
77
|
+
|
78
|
+
iex> Phone.pretty("212-555-0100")
|
79
|
+
"(212) 555-0100"
|
80
|
+
|
81
|
+
iex> Phone.pretty("212-155-0100")
|
82
|
+
"(000) 000-0000"
|
83
|
+
|
84
|
+
iex> Phone.pretty("+1 (303) 555-1212")
|
85
|
+
"(303) 555-1212"
|
86
|
+
|
87
|
+
iex> Phone.pretty("867.5309")
|
88
|
+
"(000) 000-0000"
|
51
89
|
"""
|
52
90
|
@spec pretty(String.t) :: String.t
|
53
|
-
def pretty(
|
54
|
-
|
91
|
+
def pretty(raw) do
|
92
|
+
raw
|
93
|
+
|> __MODULE__.number
|
94
|
+
|> (fn <<area_code::binary-size(3), exchange_code::binary-size(3), rest::binary>> ->
|
95
|
+
"(#{area_code}) #{exchange_code}-#{rest}"
|
96
|
+
end).()
|
55
97
|
end
|
56
98
|
end
|
@@ -7,11 +7,17 @@ defmodule Phone do
|
|
7
7
|
|
8
8
|
## Examples
|
9
9
|
|
10
|
-
iex> Phone.number("
|
11
|
-
"
|
10
|
+
iex> Phone.number("212-555-0100")
|
11
|
+
"2125550100"
|
12
12
|
|
13
|
-
iex> Phone.number("+1 (
|
14
|
-
"
|
13
|
+
iex> Phone.number("+1 (212) 555-0100")
|
14
|
+
"2125550100"
|
15
|
+
|
16
|
+
iex> Phone.number("+1 (212) 055-0100")
|
17
|
+
"0000000000"
|
18
|
+
|
19
|
+
iex> Phone.number("(212) 555-0100")
|
20
|
+
"2125550100"
|
15
21
|
|
16
22
|
iex> Phone.number("867.5309")
|
17
23
|
"0000000000"
|
@@ -28,11 +34,14 @@ defmodule Phone do
|
|
28
34
|
|
29
35
|
## Examples
|
30
36
|
|
31
|
-
iex> Phone.area_code("
|
32
|
-
"
|
37
|
+
iex> Phone.area_code("212-555-0100")
|
38
|
+
"212"
|
33
39
|
|
34
|
-
iex> Phone.area_code("+1 (
|
35
|
-
"
|
40
|
+
iex> Phone.area_code("+1 (212) 555-0100")
|
41
|
+
"212"
|
42
|
+
|
43
|
+
iex> Phone.area_code("+1 (012) 555-0100")
|
44
|
+
"000"
|
36
45
|
|
37
46
|
iex> Phone.area_code("867.5309")
|
38
47
|
"000"
|
@@ -49,8 +58,11 @@ defmodule Phone do
|
|
49
58
|
|
50
59
|
## Examples
|
51
60
|
|
52
|
-
iex> Phone.pretty("
|
53
|
-
"(
|
61
|
+
iex> Phone.pretty("212-555-0100")
|
62
|
+
"(212) 555-0100"
|
63
|
+
|
64
|
+
iex> Phone.pretty("212-155-0100")
|
65
|
+
"(000) 000-0000"
|
54
66
|
|
55
67
|
iex> Phone.pretty("+1 (303) 555-1212")
|
56
68
|
"(303) 555-1212"
|
@@ -9,56 +9,81 @@ defmodule PhoneTest do
|
|
9
9
|
use ExUnit.Case
|
10
10
|
|
11
11
|
test "cleans number" do
|
12
|
-
assert Phone.number("(
|
12
|
+
assert Phone.number("(212) 555-0100") == "2125550100"
|
13
13
|
end
|
14
14
|
|
15
15
|
@tag :pending
|
16
16
|
test "cleans number with dots" do
|
17
|
-
assert Phone.number("
|
17
|
+
assert Phone.number("212.555.0100") == "2125550100"
|
18
18
|
end
|
19
19
|
|
20
20
|
@tag :pending
|
21
21
|
test "valid when 11 digits and first is 1" do
|
22
|
-
assert Phone.number("
|
22
|
+
assert Phone.number("12125550100") == "2125550100"
|
23
23
|
end
|
24
24
|
|
25
25
|
@tag :pending
|
26
|
-
test "
|
27
|
-
assert Phone.number("
|
26
|
+
test "valid when 11 digits and some decorations" do
|
27
|
+
assert Phone.number("+1 (212) 555-0100") == "2125550100"
|
28
|
+
end
|
29
|
+
|
30
|
+
@tag :pending
|
31
|
+
test "invalid when country calling code is not 1" do
|
32
|
+
assert Phone.number("22125550100") == "0000000000"
|
28
33
|
end
|
29
34
|
|
30
35
|
@tag :pending
|
31
36
|
test "invalid when 9 digits" do
|
32
|
-
assert Phone.number("
|
37
|
+
assert Phone.number("212555010") == "0000000000"
|
33
38
|
end
|
34
39
|
|
35
40
|
@tag :pending
|
36
41
|
test "invalid when proper number of digits but letters mixed in" do
|
37
|
-
assert Phone.number("
|
42
|
+
assert Phone.number("2a1a2a5a5a5a0a1a0a0a") == "0000000000"
|
38
43
|
end
|
39
44
|
|
40
45
|
@tag :pending
|
41
46
|
test "invalid with correct number of characters but some are letters" do
|
42
|
-
assert Phone.number("
|
47
|
+
assert Phone.number("2a1a2a5a5a") == "0000000000"
|
48
|
+
end
|
49
|
+
|
50
|
+
@tag :pending
|
51
|
+
test "invalid when area code begins with 1" do
|
52
|
+
assert Phone.number("1125550100") == "0000000000"
|
53
|
+
end
|
54
|
+
|
55
|
+
@tag :pending
|
56
|
+
test "invalid when area code begins with 0" do
|
57
|
+
assert Phone.number("0125550100") == "0000000000"
|
58
|
+
end
|
59
|
+
|
60
|
+
@tag :pending
|
61
|
+
test "invalid when exchange code begins with 1" do
|
62
|
+
assert Phone.number("2121550100") == "0000000000"
|
63
|
+
end
|
64
|
+
|
65
|
+
@tag :pending
|
66
|
+
test "invalid when exchange code begins with 0" do
|
67
|
+
assert Phone.number("2120550100") == "0000000000"
|
43
68
|
end
|
44
69
|
|
45
70
|
@tag :pending
|
46
71
|
test "area code" do
|
47
|
-
assert Phone.area_code("
|
72
|
+
assert Phone.area_code("2125550100") == "212"
|
48
73
|
end
|
49
74
|
|
50
75
|
@tag :pending
|
51
76
|
test "area code with full US phone number" do
|
52
|
-
assert Phone.area_code("
|
77
|
+
assert Phone.area_code("12125550100") == "212"
|
53
78
|
end
|
54
79
|
|
55
80
|
@tag :pending
|
56
81
|
test "pretty print" do
|
57
|
-
assert Phone.pretty("
|
82
|
+
assert Phone.pretty("2125550100") == "(212) 555-0100"
|
58
83
|
end
|
59
84
|
|
60
85
|
@tag :pending
|
61
86
|
test "pretty print with full US phone number" do
|
62
|
-
assert Phone.pretty("
|
87
|
+
assert Phone.pretty("12125550100") == "(212) 555-0100"
|
63
88
|
end
|
64
89
|
end
|