which_osx 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/version.rb +1 -1
- data/lib/which_osx.rb +34 -4
- data/spec/which_osx_spec.rb +18 -0
- metadata +1 -1
data/lib/version.rb
CHANGED
data/lib/which_osx.rb
CHANGED
@@ -1,14 +1,44 @@
|
|
1
1
|
# A simple tool to determine the current version of Mac OS X.
|
2
|
-
|
2
|
+
|
3
|
+
# Regex for "##.#.#"
|
4
|
+
output = `sw_vers`.scan(/\d\d\.\d\.\d/).flatten.to_s
|
5
|
+
|
6
|
+
# Take out some weird bits
|
7
|
+
output.delete! "[]\""
|
8
|
+
VERSION = output
|
3
9
|
|
4
10
|
module WhichOSX
|
5
11
|
def self.version
|
6
|
-
|
7
|
-
|
8
|
-
return output
|
12
|
+
short_version = VERSION
|
13
|
+
return short_version
|
9
14
|
|
10
15
|
rescue Errno::ENOENT
|
11
16
|
puts "It looks like you aren't using Mac OS X. Sorry!"
|
12
17
|
|
13
18
|
end
|
19
|
+
|
20
|
+
def self.full_version
|
21
|
+
full_version = "Mac OS X " + VERSION
|
22
|
+
return full_version
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.short_name
|
26
|
+
# We just want the major versions -- 10.6, 10.7, etc.
|
27
|
+
major_version = VERSION.chop.chop
|
28
|
+
|
29
|
+
case
|
30
|
+
when major_version == "10.4"
|
31
|
+
short_name = "Tiger"
|
32
|
+
when major_version == "10.5"
|
33
|
+
short_name = "Leopard"
|
34
|
+
when major_version == "10.6"
|
35
|
+
short_name = "Snow Leopard"
|
36
|
+
when major_version == "10.7"
|
37
|
+
short_name = "Lion"
|
38
|
+
when major_version == "10.8"
|
39
|
+
short_name = "Mountain Lion"
|
40
|
+
end
|
41
|
+
|
42
|
+
return short_name
|
43
|
+
end
|
14
44
|
end
|
data/spec/which_osx_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# which_osx_spec.rb
|
2
|
+
# todo: mock this so we don't encounter errors when we update our OS
|
3
|
+
|
2
4
|
require 'which_osx'
|
3
5
|
|
4
6
|
describe "version" do
|
@@ -13,5 +15,21 @@ require 'which_osx'
|
|
13
15
|
# it "should tell you when you're not on Mac OS X" do
|
14
16
|
# # how best to mock a non-Mac OS X environment?
|
15
17
|
# end
|
18
|
+
end
|
16
19
|
|
20
|
+
describe "full version" do
|
21
|
+
it "should return the full name of the OS" do
|
22
|
+
WhichOSX.full_version.should === "Mac OS X 10.7.3"
|
23
|
+
end
|
17
24
|
end
|
25
|
+
|
26
|
+
describe "short name" do
|
27
|
+
it "should chomp the version into a major release number" do
|
28
|
+
WhichOSX.version.chop.chop.should === "10.7"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return a major release name (Lion, Leopard, etc.)" do
|
32
|
+
WhichOSX.short_name.should === "Lion"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|