Skip to content

Instantly share code, notes, and snippets.

@jlao
Created August 1, 2010 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlao/502972 to your computer and use it in GitHub Desktop.
Save jlao/502972 to your computer and use it in GitHub Desktop.
abstract class Status {
import java.util.Date
val id: Long
val text: String
val createdAt: Date
val user: User
val inReplyToStatusID: Option[Int]
val inReplyToUserID: Option[Int]
val inReplyToScreenName: Option[String]
override def equals(that: Any): Boolean = that match {
case s: Status => {
id == s.id && text == s.text && createdAt == s.createdAt &&
user == s.user && inReplyToStatusID == s.inReplyToStatusID &&
inReplyToUserID == s.inReplyToUserID &&
inReplyToScreenName == s.inReplyToScreenName
}
case _ => false
}
override def toString =
"{ id => " + id + ", text => " + text + ", createdAt => " + createdAt +
", user => " + user + ", inReplyToStatusID => " + inReplyToStatusID +
", inReplyToUserID => " + inReplyToUserID + ", inReplyToScreenName => " +
inReplyToScreenName + " }"
}
object Status {
import scala.xml._
import com.cardinal.util.DateParser
def apply(xml: NodeSeq): Status = fromXML(xml)
def fromXML(xml: NodeSeq): Status = {
new Status {
val id = (xml \ "id").text.toLong
val text = (xml \ "text").text
val createdAt = DateParser parse (xml \ "created_at").text
val user = User(xml \ "user")
val inReplyToStatusID = {
val text: String = (xml \ "in_reply_to_status_id").text
if (text equals "") None else Some(text.toInt)
}
val inReplyToUserID = {
val text: String = (xml \ "in_reply_to_user_id").text
if (text equals "") None else Some(text.toInt)
}
val inReplyToScreenName = {
val text: String = (xml \ "in_reply_to_screen_name").text
if (text equals "") None else Some(text)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment