Class: Sapristi::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/sapristi/definition.rb

Constant Summary collapse

TRANSLATIONS =
{
  'H-size' => 'work_area_width', 'V-size' => 'work_area_height',
  'X-position' => 'work_area_width', 'Y-position' => 'work_area_height'
}.freeze
NUMERIC_FIELDS =
(TRANSLATIONS.keys + %w[Workspace]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition_hash) ⇒ Definition

Returns a new instance of Definition.



11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def command
  @command
end

#h_sizeObject (readonly)

Returns the value of attribute h_size.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def h_size
  @h_size
end

#monitorObject (readonly)

Returns the value of attribute monitor.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def monitor
  @monitor
end

#raw_definitionObject (readonly)

Returns the value of attribute raw_definition.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def raw_definition
  @raw_definition
end

#titleObject (readonly)

Returns the value of attribute title.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def title
  @title
end

#v_sizeObject (readonly)

Returns the value of attribute v_size.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def v_size
  @v_size
end

#workspaceObject (readonly)

Returns the value of attribute workspace.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def workspace
  @workspace
end

#x_positionObject (readonly)

Returns the value of attribute x_position.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def x_position
  @x_position
end

#y_positionObject (readonly)

Returns the value of attribute y_position.



24
25
26
# File 'lib/sapristi/definition.rb', line 24

def y_position
  @y_position
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



30
31
32
# File 'lib/sapristi/definition.rb', line 30

def ==(other)
  other.class == self.class && state == other.state
end

#hashObject



26
27
28
# File 'lib/sapristi/definition.rb', line 26

def hash
  state.hash
end

#to_sObject



20
21
22
# File 'lib/sapristi/definition.rb', line 20

def to_s
  HEADERS.map { |key| "#{key}: #{raw_definition[key]}" }.join(', ')
end