class Sapristi::Definition
Constants
- HEADERS
- NUMERIC_FIELDS
- TRANSLATIONS
Attributes
command[R]
group[R]
height[R]
monitor[R]
raw_definition[R]
title[R]
width[R]
workspace[R]
x[R]
y[R]
Public Class Methods
new(definition_hash)
click to toggle source
# File lib/sapristi/definition.rb, line 11 def initialize(definition_hash) validate_raw definition_hash @raw_definition = definition_hash.to_h.clone @monitor = MonitorManager.new.get_monitor_or_main definition_hash['Monitor'] @workspace = WindowManager.new.find_workspace_or_current definition_hash['Workspace']&.to_i normalize_variables end
Public Instance Methods
==(other)
click to toggle source
# File lib/sapristi/definition.rb, line 31 def ==(other) other.class == self.class && state == other.state end
Also aliased as: eql?
hash()
click to toggle source
# File lib/sapristi/definition.rb, line 27 def hash state.hash end
to_s()
click to toggle source
# File lib/sapristi/definition.rb, line 20 def to_s HEADERS.map { |key| "#{key}: #{raw_definition[key]}" }.join(', ') end
Protected Instance Methods
state()
click to toggle source
# File lib/sapristi/definition.rb, line 39 def state raw_definition end
Private Instance Methods
normalize_variables()
click to toggle source
# File lib/sapristi/definition.rb, line 45 def normalize_variables %w[Title Command X Y Width Height Group].each do |key| name = key.downcase.gsub(/-/, '_') value = AttributeNormalizer.new(key, @raw_definition[key], @monitor).normalize instance_variable_set "@#{name}".to_sym, value end end
validate_geometry(definition)
click to toggle source
# File lib/sapristi/definition.rb, line 62 def validate_geometry(definition) geometry_field_nil = %w[Width Height X Y].find { |key| definition[key].nil? } raise Error, "No #{geometry_field_nil} specified" if geometry_field_nil end
validate_headers(definition)
click to toggle source
# File lib/sapristi/definition.rb, line 69 def validate_headers(definition) headers = definition.keys return if Set.new(HEADERS).superset?(Set.new(headers)) actual_headers = headers.join(', ') expected_headers = HEADERS.join(', ') raise Error, "Invalid configuration file: invalid headers=#{actual_headers}, valid=#{expected_headers}" end
validate_raw(definition)
click to toggle source
# File lib/sapristi/definition.rb, line 53 def validate_raw(definition) validate_headers(definition) raise Error, 'No command or window title specified' unless definition['Command'] || definition['Title'] validate_geometry(definition) raise Error, "Invalid monitor=#{definition['Monitor']}" if definition['Monitor']&.to_i&.negative? end