summaryrefslogtreecommitdiff
path: root/src/metadata/MetadataRational.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/metadata/MetadataRational.vala')
-rw-r--r--src/metadata/MetadataRational.vala26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/metadata/MetadataRational.vala b/src/metadata/MetadataRational.vala
new file mode 100644
index 0000000..ec3ac17
--- /dev/null
+++ b/src/metadata/MetadataRational.vala
@@ -0,0 +1,26 @@
+public struct MetadataRational {
+ public int numerator;
+ public int denominator;
+
+ public MetadataRational.invalid() {
+ this.numerator = -1;
+ this.denominator = -1;
+ }
+
+ public MetadataRational(int numerator, int denominator) {
+ this.numerator = numerator;
+ this.denominator = denominator;
+ }
+
+ private bool is_component_valid(int component) {
+ return (component >= 0) && (component <= 1000000);
+ }
+
+ public bool is_valid() {
+ return (is_component_valid(numerator) && is_component_valid(denominator));
+ }
+
+ public string to_string() {
+ return (is_valid()) ? ("%d/%d".printf(numerator, denominator)) : "";
+ }
+}