-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
145 additions
and
27 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
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
36 changes: 36 additions & 0 deletions
36
scalawiki-bots/src/main/scala/org/scalawiki/bots/np/WlmContacts.scala
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.scalawiki.bots.np | ||
|
||
import scala.io.Source | ||
import scala.util.matching.Regex | ||
|
||
object WlmContacts { | ||
|
||
private val Number = """[ +][\d\-()\s]{10,}""".r | ||
private val Lengths = Set(10, 12) | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(getNumbers.size) | ||
getNumbers.foreach(println) | ||
} | ||
|
||
def getLines: Seq[String] = { | ||
val source = Source.fromFile("c:\\wmua\\np\\progress.txt") | ||
source.getLines().toSeq | ||
} | ||
|
||
def getNumbers: Seq[String] = { | ||
getLines.flatMap(getNumber) | ||
} | ||
|
||
def getNumber(line: String): Seq[String] = { | ||
Number | ||
.findAllIn(line) | ||
.toSeq | ||
.map(_.filter(_.isDigit)) | ||
.collect { | ||
case n if n.length == 10 => "38" + n | ||
case n if n.length == 12 => n | ||
} | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
scalawiki-bots/src/test/scala/org/scalawiki/bots/np/WlmContactsSpec.scala
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.scalawiki.bots.np | ||
|
||
import org.specs2.mutable.Specification | ||
|
||
class WlmContactsSpec extends Specification{ | ||
|
||
"WlmContacts" should { | ||
"pick 10 digits" in { | ||
WlmContacts.getNumbers.contains("0932563441") === true | ||
} | ||
|
||
"pick 12 digits" in { | ||
WlmContacts.getNumbers.contains("380675488100") === true | ||
} | ||
|
||
"pick dashed/spaced/braced digits" in { | ||
WlmContacts.getNumbers.contains("063-370-49-59") === true | ||
WlmContacts.getNumbers.contains("097 535-70-10") === true | ||
WlmContacts.getNumbers.contains("095 664 17 25") === true | ||
WlmContacts.getNumbers.contains("095-0415177") === true | ||
WlmContacts.getNumbers.contains("(097)9398937") === true | ||
WlmContacts.getNumbers.contains("380 (63) 788 27 00") === true | ||
WlmContacts.getNumbers.contains("38 050 801 52 49") === true | ||
|
||
|
||
} | ||
} | ||
} |