-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
extractors.scala
70 lines (62 loc) · 2.21 KB
/
extractors.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package lgbt.princess.v.semver
import lgbt.princess.v.semver.Identifiers._
/**
* This extractor is for extracting the version core and pre-release identifiers
* of a SemVer version. If you want to extract build identifiers as well,
* use the [[:- `:-`]] extractor instead. Sadly, there is no way to have both
* functionalities in the same extractor.
*/
object - {
/**
* Extracts the version core and pre-release identifiers from a SemVer
* version.
*/
def unapply(sv: SemVer): Option[(Core, PreRelease)] = {
if (sv.build.isDefined || sv.preRelease.isEmpty) None
else Some((sv.core, sv.preRelease.get))
}
}
/**
* This extractor is for extracting the version core of a SemVer version,
* and is for use specifically with the [[+ `+`]] extractor (which
* extracts the pre-release identifiers and build identifiers). If you
* only want to extract the core and pre-release identifiers, use the
* [[- `-`]] extractor instead.
*/
object :- {
/**
* Extracts the version core from a SemVer version and leaves the
* pre-release identifiers and build identifiers partially extracted.
*/
def unapply(sv: SemVer): Option[(Core, (PreRelease, Option[Build]))] =
sv match {
case SemVer(core, Some(preRelease), build) => Some((core, (preRelease, build)))
case _ => None
}
}
/**
* This extractor is for extracting the version core and build
* identifiers of a SemVer version, or for extracting the pre-release
* identifiers and build-identifiers when the version core has already
* been extracted by the [[:- `:-`]] extractor.
*/
object + {
/**
* Extracts the version core and build identifiers from a SemVer
* version.
*/
def unapply(sv: SemVer): Option[(Core, Build)] =
sv match {
case SemVer(core, None, Some(build)) => Some((core, build))
case _ => None
}
/**
* Extracts the pre-release identifiers and build identifiers from
* a partially extracted SemVer version.
*/
def unapply(arg: (PreRelease, Option[Build])): Option[(PreRelease, Build)] =
arg match {
case (preRelease, Some(build)) => Some((preRelease, build))
case _ => None
}
}