aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-semver
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-semver')
-rw-r--r--crates/shirabe-semver/src/comparator.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/crates/shirabe-semver/src/comparator.rs b/crates/shirabe-semver/src/comparator.rs
index 15df53e..575a656 100644
--- a/crates/shirabe-semver/src/comparator.rs
+++ b/crates/shirabe-semver/src/comparator.rs
@@ -1 +1,36 @@
//! ref: composer/vendor/composer/semver/src/Comparator.php
+
+use crate::constraint::constraint::Constraint;
+
+pub struct Comparator;
+
+impl Comparator {
+ pub fn greater_than(version1: String, version2: String) -> bool {
+ Self::compare(version1, ">".to_string(), version2)
+ }
+
+ pub fn greater_than_or_equal_to(version1: String, version2: String) -> bool {
+ Self::compare(version1, ">=".to_string(), version2)
+ }
+
+ pub fn less_than(version1: String, version2: String) -> bool {
+ Self::compare(version1, "<".to_string(), version2)
+ }
+
+ pub fn less_than_or_equal_to(version1: String, version2: String) -> bool {
+ Self::compare(version1, "<=".to_string(), version2)
+ }
+
+ pub fn equal_to(version1: String, version2: String) -> bool {
+ Self::compare(version1, "==".to_string(), version2)
+ }
+
+ pub fn not_equal_to(version1: String, version2: String) -> bool {
+ Self::compare(version1, "!=".to_string(), version2)
+ }
+
+ pub fn compare(version1: String, operator: String, version2: String) -> bool {
+ let constraint = Constraint::new(operator, version2);
+ constraint.match_specific(&Constraint::new("==".to_string(), version1), true)
+ }
+}