Created
June 1, 2012 12:31
-
-
Save rockpapergoat/2851806 to your computer and use it in GitHub Desktop.
extension attribute to get model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
def get_model | |
# using awk is way simpler, but i wanted to see if i could use just ruby. | |
#model = %x(system_profiler SPHardwareDataType | awk '/Model Identifier:/ {print $NF}') | |
# changed to use string.match to make it less ugly. still ugly, though. | |
model = %x(system_profiler SPHardwareDataType).match(/Model Identifier:\ .+$/).to_s.split(":").last.strip | |
end | |
def report_model(model) | |
if model =~ /(Air|Book)/ | |
puts "<result>Laptop</result>" | |
elsif model =~ /(iMac|MacPro|Mini)/ | |
puts "<result>Desktop</result>" | |
end | |
end | |
report_model(get_model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment