aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/version.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb
new file mode 100644
index 000000000..f03510a68
--- /dev/null
+++ b/Library/Homebrew/version.rb
@@ -0,0 +1,25 @@
+class Version
+ include Comparable
+
+ def initialize val
+ return val if val.is_a? Version or val.nil?
+ @version = val.to_s.strip
+ end
+
+ def nums
+ @version.scan(/\d+/).map { |d| d.to_i }
+ end
+
+ def <=>(other)
+ @version <=> other.version
+ end
+
+ def to_s
+ @version
+ end
+ alias_method :to_str, :to_s
+
+ def self.parse spec
+ Pathname.new(spec.to_s).version
+ end
+end