Class: Windows::Units::UnitConverter

Inherits:
Object
  • Object
show all
Includes:
Structures, Converter, Recognizer
Defined in:
lib/windows/units/unit_converter.rb

Constant Summary collapse

NAMED_GEOMETRY =
{
  left:         [0,  0,  '50%',  '100%'],
  right:        ['50%', 0,  '50%',  '100%'],
  bottom:       [0,  '50%', '100%', '50%'],
  top:          [0,  0,  '100%', '50%'], 
  max:          [0,  0,  '100%', '100%'],
  bottom_right: ['50%', '50%', '50%', '50%'],
  bottom_left:  [0, '50%', '50%', '50%'],
  top_right:    ['50%', 0, '50%', '50%'],
  top_left:     [0, 0, '50%', '50%']
}

Instance Method Summary collapse

Methods included from Recognizer

#recognize_unit

Methods included from Converter

#converter

Constructor Details

#initialize(desktop, *args) ⇒ UnitConverter

Returns a new instance of UnitConverter.



24
25
26
27
28
29
30
31
32
# File 'lib/windows/units/unit_converter.rb', line 24

def initialize(desktop, *args)
  @width    = desktop.width
  @height   = desktop.height
  @geometry = create_geometry(args)
  @x_offset = desktop.x_offset
  @y_offset = desktop.y_offset
  @x_axis   = [@geometry.x, @geometry.w]
  @y_axis   = [@geometry.y, @geometry.h]
end

Instance Method Details

#convertObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/windows/units/unit_converter.rb', line 34

def convert
  x, w = @x_axis.map do |el|
    item = recognize_unit(el)
    converter(item.unit).to(item.format, base: @width)
  end

  y, h = @y_axis.map do |el|
    item = recognize_unit(el)
    converter(item.unit).to(item.format, base: @height)
  end

  x = x + @x_offset
  y = y + @y_offset

  [x, y, w, h]
end