aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2012-07-09 22:51:10 -0500
committerJack Nagel2012-08-18 11:12:07 -0500
commit104fc0e09b8bfe825a0fecd71a971677cb11c271 (patch)
tree98ae6238d77dc26a3dc5181dda4a7dfb99ceeb94 /Library
parent1a8d5357215daaa2637e02ecfbb657c7b669b3a4 (diff)
downloadbrew-104fc0e09b8bfe825a0fecd71a971677cb11c271.tar.bz2
Add Version class
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