Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Rose committed Aug 23, 2011
0 parents commit 4a9aa49
Show file tree
Hide file tree
Showing 200 changed files with 7,362 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build.sbt
@@ -0,0 +1,7 @@
name := "Todo.txt Scala"

version := "0.1"

organization := "com.lbak"

scalaVersion := "2.8.1"
Binary file added lib/specs_2.8.1-1.6.7.jar
Binary file not shown.
Binary file not shown.
Binary file added project/boot/scala-2.8.1/lib/jline.jar
Binary file not shown.
Binary file added project/boot/scala-2.8.1/lib/scala-compiler.jar
Binary file not shown.
Binary file added project/boot/scala-2.8.1/lib/scala-library.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2,616 changes: 2,616 additions & 0 deletions project/boot/update.log

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions project/build.properties
@@ -0,0 +1 @@
sbt.version=0.10.1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
35 changes: 35 additions & 0 deletions src/main/scala/Task.scala
@@ -0,0 +1,35 @@
package com.lbak.todo

import scala.util.matching.Regex

class Task(val orig: String) {
private val PriorityRegex = new Regex("""^\(([A-Za-z])\)\s+.*?""")
private val ContextsRegex = new Regex("""(?:\s+|^)@\w+""")
private val ProjectsRegex = new Regex("""(?:\s+|^)\+\w+""")

lazy val priority = getPriority()
lazy val contexts = getContexts()
lazy val projects = getProjects()
lazy val text = getText()

private def getPriority(): String = orig match {
case PriorityRegex(priorityMatch) => priorityMatch
case _ => null // Do Nothing
}

private def getContexts(): List[String] = {
ContextsRegex.findAllIn(orig).toList.map(_.trim)
}

private def getProjects(): List[String] = {
ProjectsRegex.findAllIn(orig).toList.map(_.trim)
}

private def getText(): String = {
orig.replaceAll(PriorityRegex.toString, "").
replaceAll(ContextsRegex.toString, "").
replaceAll(ProjectsRegex.toString, "").
replaceAll("""\s+""", " ").
trim
}
}
7 changes: 7 additions & 0 deletions src/main/scala/TodoApp.scala
@@ -0,0 +1,7 @@
package com.lbak.todo

object TodoApp {
def main(args: Array[String]) {

}
}
10 changes: 10 additions & 0 deletions src/main/scala/TodoList.scala
@@ -0,0 +1,10 @@
package com.lbak.todo

import scala.io.Source

class TodoList(val path: String) {
/**
*
*/
val tasks = Source.fromFile(path).getLines.map(new Task(_))
}
46 changes: 46 additions & 0 deletions src/test/scala/TaskSpec.scala
@@ -0,0 +1,46 @@
package com.lbak.todo.test

import org.specs._
import com.lbak.todo.Task

class TaskSpec extends Specification {
val task = new Task("(A) This task has all sorts. @context +project")
val dud = new Task(" (B) Failed@priority and 2+2 is 4!")

"Task" should {
"recognise priority" >> {
task.priority must_== "A"
}

"recognise contexts" >> {
task.contexts must contain("@context")
}

"recognise projects" >> {
task.projects must contain("+project")
}

"extract text correctly" >> {
task.text must_== "This task has all sorts."
}
}

"Dud task" should {
"not match priority" >> {
dud.priority must beNull
}

"not match context" >> {
dud.contexts must beEmpty
}

"not match projects" >> {
dud.projects must beEmpty
}

"still match text" >> {
// It has no leading space because the .text gets trimmed.
dud.text must_== "(B) Failed@priority and 2+2 is 4!"
}
}
}
27 changes: 27 additions & 0 deletions src/test/scala/TodoListSpec.scala
@@ -0,0 +1,27 @@
package com.lbak.todo.test

import com.lbak.todo.TodoList
import com.lbak.todo.Task
import org.specs._
import java.io.File

class TodoListSpec extends Specification {
// Get the test data file. Pretty hacky but it'll do for now.
val path = new File(".").getAbsolutePath().stripSuffix(".") +
"src/test/scala/data/todo.txt"
// Create a TodoList out of the path given.
val list = new TodoList(path)

"TodoList" should {
"grab a list of Tasks" >> {
var allTasks = true
list.tasks.foreach({ task =>
if (!task.isInstanceOf[Task]) {
allTasks = false
}
})

allTasks must beTrue
}
}
}
5 changes: 5 additions & 0 deletions src/test/scala/data/todo.txt
@@ -0,0 +1,5 @@
(A) Crack the Da Vinci Code.
(B) +winning Win.
@context Give it some context.
Just a POD: Plain old task.
(C) +project @context This one has it all!
13 changes: 13 additions & 0 deletions target/.history
@@ -0,0 +1,13 @@
run
console
~compile
test
console
~test
build
package
publish
console
test
~test
test
79 changes: 79 additions & 0 deletions target/scala-2.8.1.final/api/com/lbak/package.html
@@ -0,0 +1,79 @@
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>com.lbak</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

<link href="../../lib/template.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="../../lib/jquery.js"></script>
<script type="text/javascript" src="../../lib/jquery-ui.js"></script>
<script type="text/javascript" src="../../lib/template.js"></script>
<script type="text/javascript" src="../../lib/tools.tooltip.js"></script>

</head>
<body class="value" onload="windowTitle();">

<p id="owner"><a href="../package.html" class="extype" name="com">com</a></p>

<div id="definition">
<img src="../../lib/package_big.png" />
<h1>lbak</h1>
</div>

<h4 class="signature" id="signature">
<span class="kind">package</span>
<span class="symbol">
<span class="name">lbak</span>



</span>
</h4>
<div class="fullcomment" id="comment"></div>

<div id="template">

<div id="mbrsel">
<div id="textfilter"><span class="pre"></span><span class="input"><input accesskey="/" type="text" /></span><span class="post"></span></div>


<div id="visbl">
<span class="filtertype">Visibility</span>
<ol><li class="public in">Public</li><li class="all out">All</li></ol>
</div>
<div id="impl">
<span class="filtertype">Impl.</span>
<ol><li class="concrete in">Concrete</li><li class="abstract in">Abstract</li></ol>
</div>
</div>





<div class="values members" id="values">
<h3>Value Members</h3>
<ol><li visbl="pub" data-isabs="false" name="com.lbak.todo">
<a id="todo:todo"></a>
<h4 class="signature"><a href="todo/package.html">
<span class="kind">package</span>
<span class="symbol">
<span class="name">todo</span>



</span>
</a></h4>

</li></ol>
</div>



</div>

<div id="tooltip"></div>

</body>
</html>

0 comments on commit 4a9aa49

Please sign in to comment.