Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created June 1, 2012 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rockpapergoat/2851806 to your computer and use it in GitHub Desktop.
Save rockpapergoat/2851806 to your computer and use it in GitHub Desktop.
extension attribute to get model
#!/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