Extractor

com.phasmidsoftware.xmldoc.xml.Extractor
See theExtractor companion trait
object Extractor

Companion object to Extractor.

Attributes

Companion
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Extractor.type

Members list

Type members

Classlikes

object charSequenceExtractor extends Extractor[CharSequence]

CharSequence extractor.

CharSequence extractor.

Attributes

Supertypes
trait Extractor[CharSequence]
trait NamedFunction[Extractor[CharSequence]]
class Object
trait Matchable
class Any
Self type

Value members

Concrete methods

def apply[T](extractorFunc: Node => Try[T]): Extractor[T]

Method to create an Extractor[T] from a Node => Try[T] function. Note that this isn't strictly necessary because of the SAM conversion mechanism which turns a Node => Try[T] function into an Extractor[T].

Method to create an Extractor[T] from a Node => Try[T] function. Note that this isn't strictly necessary because of the SAM conversion mechanism which turns a Node => Try[T] function into an Extractor[T].

Type parameters

T

the underlying type of the resulting Extractor.

Value parameters

extractorFunc

a Node => Try[T] function.

Attributes

Returns

an Extractor[T].

def apply[T](ty: => Try[T]): Extractor[T]

Method to create an Extractor[T] such that the result of the extraction is always a constant, regardless of what's in the node provided.

Method to create an Extractor[T] such that the result of the extraction is always a constant, regardless of what's in the node provided.

Type parameters

T

the underlying type of the result.

Value parameters

ty

a Try[T].

Attributes

Returns

an Extractor[T] which always produces ty when extract is invoked on it.

def createLazy[T](te: => Extractor[T]): Extractor[T]

Method to create a lazy Extractor[T] from an explicit Extractor[T] which is call-by-name. The purpose of this method is to break the infinite recursion caused when implicit values are defined recursively. See the Play JSON library method in JsPath called lazyRead.

Method to create a lazy Extractor[T] from an explicit Extractor[T] which is call-by-name. The purpose of this method is to break the infinite recursion caused when implicit values are defined recursively. See the Play JSON library method in JsPath called lazyRead.

Type parameters

T

the underlying type of the input and output Extractors.

Value parameters

te

an Extractor[T].

Attributes

Returns

an Extractor[T].

def extract[T : Extractor](node: Node): Try[T]

Method to extract a Try[T] from the implicitly defined extractor operating on the given node.

Method to extract a Try[T] from the implicitly defined extractor operating on the given node.

Type parameters

T

the underlying result type. Required: implicit evidence of an Extractor[T].

Value parameters

node

the node on which the extractor will work.

Attributes

Returns

a Try[T].

def extractAll[T : MultiExtractor](node: Node): Try[T]

Method to extract all possible Try[T] from the implicitly defined multi-extractor operating on the given nodes. Usually, T is itself an Iterable type.

Method to extract all possible Try[T] from the implicitly defined multi-extractor operating on the given nodes. Usually, T is itself an Iterable type.

The difference between this method and extractMulti is that a Node is passed in, rather than a NodeSeq.

Type parameters

T

the underlying result type. Required: implicit evidence of a MultiExtractor[T].

Value parameters

node

the node on which the extractor will work--it will extract from all the node's children.

Attributes

Returns

a Try[T].

def extractChildren[P : MultiExtractor](member: String)(node: Node): Try[P]

Method to extract child elements from a node.

Method to extract child elements from a node.

CONSIDER rewriting this method: it has ended up being a huge a hack and needs work!! NOTE: There are four different ways to get a successful result: (1) node / member yields a non-empty result which is passed into extractMulti; (2) TagProperties.mustMatch(member) in which case the result will be empty; (3) extractAll(node) yields a successful non-empty result, which is returned; (4) extractAll(node) yields a successful empty result, in which case ChildNames.translate(member) is used to match children.

Type parameters

P

the underlying type of the result. Required: implicit evidence of type MultiExtractor[P].

Value parameters

member

the name of the element(s) to extract, according to the construct function (typically, this means the name of the member in a case class).

node

the node from which we want to extract.

Attributes

Returns

a Try[P].

def extractElementsByLabel[P : Extractor](nodeSeq: NodeSeq, label: String): Seq[Try[P]]

Method to extract a Seq or Try[P] from a NodeSeq, by filtering on the given label.

Method to extract a Seq or Try[P] from a NodeSeq, by filtering on the given label.

Type parameters

P

the underlying type of the result. Required: implicit evidence of type Extractor[P].

Value parameters

label

the label to match.

nodeSeq

the nodes whence to extract.

Attributes

Returns

a Seq of Try[P].

def extractMulti[T : MultiExtractor](nodeSeq: NodeSeq): Try[T]

Method to extract a Try[T] from the implicitly defined multi-extractor operating on the given nodes. Usually, T is itself an Iterable type.

Method to extract a Try[T] from the implicitly defined multi-extractor operating on the given nodes. Usually, T is itself an Iterable type.

NOTE that each implicit instanced of a MultiExtractor[T] has its own definition of Range.

Type parameters

T

the underlying result type. Required: implicit evidence of a MultiExtractor[T].

Value parameters

nodeSeq

the nodes on which the extractor will work.

Attributes

Returns

a Try[T].

def extractSequence[P : Extractor](nodeSeq: NodeSeq): Try[Seq[P]]

Method which tries to extract a sequence of objects from a NodeSeq. The difference between this method and extractMulti is in the declaration of the parametric type and its implicit evidence. The difference between this method and extractSingleton is in the result type.

Method which tries to extract a sequence of objects from a NodeSeq. The difference between this method and extractMulti is in the declaration of the parametric type and its implicit evidence. The difference between this method and extractSingleton is in the result type.

Type parameters

P

the (Extractor) type to which each individual Node should be converted. Required: implicit evidence of type Extractor[P].

Value parameters

nodeSeq

a NodeSeq.

Attributes

Returns

a Try of Seq[P].

def extractSingleton[P : Extractor](nodeSeq: NodeSeq): Try[P]

Method to extract a singleton from a NodeSeq.

Method to extract a singleton from a NodeSeq.

Type parameters

P

the underlying type of the result. Required: implicit evidence of an Extractor[P].

Value parameters

nodeSeq

a sequence of Nodes.

Attributes

Returns

a Try[P].

def fieldExtractor[P : Extractor](field: String): Extractor[P]

Method to yield a Try[P] for a particular child or attribute of the given node.

Method to yield a Try[P] for a particular child or attribute of the given node.

NOTE: Plural members should use extractChildren and not extractField.

NOTE: ideally, this should be private but is used for testing and the private method tester is struggling.

Type parameters

P

the type to which Node should be converted. Required: implicit evidence of type Extractor[P].

Value parameters

field

the name of a member field: if the (text) content of the node, then the field should be "$"; if a singleton child, then field is as is; if an attribute, then field should begin with "_"; if an optional child, then field should begin with "maybe" (the tag looked up is lower-case-initial by default, e.g. "maybeStyleUrl" looks for "styleUrl", but falls back to the capitalized form, e.g. "ExtendedData", if that's not found).

Attributes

Returns

a Try[P].

def inferAttributeType(name: String): Option[Boolean]

Method to determine, from the name of a property, whether it's an attribute or an element.

Method to determine, from the name of a property, whether it's an attribute or an element.

Value parameters

name

the member (property) name.

Attributes

Returns

Some(true) if it's an optional attribute; Some(false) if it's a required attribute; else None.

def none[T]: Extractor[T]

Method to create an Extractor[T] which always fails.

Method to create an Extractor[T] which always fails.

Type parameters

T

the underlying type of the result.

Attributes

Returns

a failing Extractor[T].

def parse[T](parser: String => Try[T]): Extractor[T]

Method to create an Extractor[T] from a String => Try[T] function.

Method to create an Extractor[T] from a String => Try[T] function.

Type parameters

T

the underlying type of the resulting Extractor.

Value parameters

parser

a String => Try[T] function.

Attributes

Returns

an Extractor[T].

Concrete fields

val attribute: Regex

Regular expression to match an attribute name, viz. _...

Regular expression to match an attribute name, viz. _...

Attributes

val flog: Flog
val logger: Logger
val optional: Regex

Regular expression to match an optional name, viz. maybe....

Regular expression to match an optional name, viz. maybe....

NOTE that the initial character of the result will have been set to lower case.

Attributes

val optionalAttribute: Regex

Regular expression to match an optional attribute name, viz. __..... With an optional attribute, it will have a default value that does not need to be overridden.

Regular expression to match an optional attribute name, viz. __..... With an optional attribute, it will have a default value that does not need to be overridden.

Attributes

Implicits

Implicits

implicit val booleanExtractor: Extractor[Boolean]

Boolean extractor. TODO use NodeParser.tryParse

Boolean extractor. TODO use NodeParser.tryParse

Attributes

implicit val doubleExtractor: Extractor[Double]

Double extractor.

Double extractor.

Attributes

implicit val intExtractor: Extractor[Int]

Int extractor.

Int extractor.

Attributes

implicit val longExtractor: Extractor[Long]

Long extractor. TODO use NodeParser.tryParse

Long extractor. TODO use NodeParser.tryParse

Attributes

implicit val unitExtractor: Extractor[Unit]

Unit extractor.

Unit extractor.

Attributes

implicit val uriExtractor: Extractor[URI]

URI extractor.

URI extractor.

NOTE: java.net.URI, not java.net.URL - KML's own "anyURI" fields (e.g. styleUrl) are frequently relative, fragment-only references (e.g. "#some-style"), which URI accepts but URL (which requires a recognized absolute scheme) rejects.

Attributes