no.arktekk.atom.extension.georss.Circle.scala Maven / Gradle / Ivy
/*
* Copyright 2012 Arktekk AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package no.arktekk.atom.extension.georss
import no.arktekk.atom.ElementWrapper
import com.codecommit.antixml.{NamespaceBinding, QName}
/**
* http://georss.org/simple
*
* @author Erlend Hamnaberg
*/
case class Circle(point: Point, radius: Int) {
def toValue(format: String) = point.toValue(format) + " " + radius
def toXML(format: String) = ElementWrapper.withNameAndText(NamespaceBinding(GeorssConstants.prefix, GeorssConstants.ns), "circle", toValue(format))
def toPointAndRadiusXML(format: String): Seq[ElementWrapper] = Seq(
point.toXML(format),
ElementWrapper.withNameAndText(NamespaceBinding(GeorssConstants.prefix, GeorssConstants.ns), "radius", radius.toString)
)
}
object Circle {
def apply(value: String): Option[Circle] = {
val grouped = value.trim.split(" ").grouped(2)
grouped.toList match {
case List(Array(x,y), Array(z)) => Some(Circle(Point(x.toDouble, y.toDouble), z.toInt))
case _ => None
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy