Created
November 30, 2015 00:10
-
-
Save kwrobert/a155377ef7d234bde7b0 to your computer and use it in GitHub Desktop.
ruby function containing array.each{} block
This file contains 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
def self.setHomeSpaces() | |
puts 'homeLayout' | |
# The name and desired number of spaces on the samsung and laptop display | |
smsng_spaces = 6 | |
laptop_spaces = 4 | |
smsng_name="S27D590" | |
laptop_name="Color LCD" | |
smsng_id = "" | |
laptop_id = "" | |
# Get the IDs for each display | |
TotalSpaces2.display_list().each { |display| | |
if display.has_value?(smsng_name) | |
smsng_id = display[:display_id] | |
elsif display.has_value?(laptop_name) | |
laptop_id = display[:display_id] | |
else | |
puts "Missing displays" | |
end | |
} | |
# Get the current number of spaces on each display | |
num_smsng_spaces = TotalSpaces2.number_of_spaces_on_display(smsng_id) | |
num_laptop_spaces = TotalSpaces2.number_of_spaces_on_display(laptop_id) | |
# Set number of spaces | |
if num_smsng_spaces < smsng_spaces | |
TotalSpaces2.add_desktops_on_display(smsng_spaces - num_smsng_spaces,smsng_id) | |
else | |
TotalSpaces2.remove_desktops_on_display(num_smsng_spaces - smsng_spaces,smsng_id) | |
end | |
if num_laptop_spaces < laptop_spaces | |
TotalSpaces2.add_desktops_on_display(laptop_spaces - num_laptop_spaces,laptop_id) | |
else | |
TotalSpaces2.remove_desktops_on_display(num_laptop_spaces - laptop_spaces,laptop_id) | |
end | |
# Set the grid layout | |
TotalSpaces2.set_grid_columns_on_display(3,smsng_id) | |
TotalSpaces2.set_grid_columns_on_display(2,laptop_id) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment