class Sapristi::DefinitionParser
Constants
- MIN_X_SIZE
- MIN_Y_SIZE
Public Class Methods
new()
click to toggle source
# File lib/sapristi/definition_parser.rb, line 5 def initialize @monitor_manager = MonitorManager.new @window_manager = WindowManager.new end
Public Instance Methods
parse(definition_hash)
click to toggle source
# File lib/sapristi/definition_parser.rb, line 10 def parse(definition_hash) definition = Definition.new(definition_hash) validate definition definition end
Private Instance Methods
validate(definition)
click to toggle source
# File lib/sapristi/definition_parser.rb, line 19 def validate(definition) validate_monitor(definition) validate_window_min_size(definition) end
validate_monitor(definition)
click to toggle source
# File lib/sapristi/definition_parser.rb, line 24 def validate_monitor(definition) monitor = definition.monitor monitor_width = monitor['x'] monitor_height = monitor['y'] validate_monitor_dimensions(definition, monitor_width, monitor_height) validate_work_area(definition, monitor_width, monitor_height) end
validate_monitor_dimensions(normalized, monitor_width, monitor_height)
click to toggle source
# File lib/sapristi/definition_parser.rb, line 33 def validate_monitor_dimensions(normalized, monitor_width, monitor_height) x_pos = normalized.x y_pos = normalized.y unless (0...monitor_width).include? x_pos raise Error, "x=#{x_pos} is outside of monitor width dimension=0..#{monitor_width - 1}" end return if (0...monitor_height).include? y_pos raise Error, "y=#{y_pos} is outside of monitor height dimension=0..#{monitor_height - 1}" end
validate_window_min_size(normalized)
click to toggle source
# File lib/sapristi/definition_parser.rb, line 59 def validate_window_min_size(normalized) window_width = normalized.width window_height = normalized.height raise Error, "window x size=#{window_width} less than #{MIN_X_SIZE}" if window_width < MIN_X_SIZE raise Error, "window y size=#{window_height} less than #{MIN_Y_SIZE}" if window_height < MIN_Y_SIZE end
validate_work_area(normalized, monitor_width, monitor_height)
click to toggle source
# File lib/sapristi/definition_parser.rb, line 44 def validate_work_area(normalized, monitor_width, monitor_height) x_pos = normalized.x y_pos = normalized.y x_end = x_pos + normalized.width y_end = y_pos + normalized.height if x_end >= monitor_width raise Error, "window x dimensions: [#{x_pos}, #{x_end}] exceeds monitor width [0..#{monitor_width - 1}]" end return if y_end < monitor_height raise Error, "window y dimensions: [#{y_pos}, #{y_end}] exceeds monitor height [0..#{monitor_height - 1}]" end