Sha256: 4ae2f24d07bdc08a5d7bbd91cc282373260a006d9fafdee6f7238933c0d76656
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
Contents
require 'virtus' require 'vedeu/support/esc' require 'vedeu/support/terminal' module Vedeu class Geometry include Virtus.model attribute :y, Integer, default: 1 attribute :x, Integer, default: 1 attribute :width, Integer, default: Terminal.width attribute :height, Integer, default: Terminal.height attribute :centred, Boolean, default: false def origin(index = 0) Esc.set_position(virtual_y[index], left) end def top if centred centre_y - (height / 2) else y end end def left if centred centre_x - (width / 2) else x end end def bottom top + height end def right left + width end def position { y: top, x: left, height: height, width: width, centred: centred, top: top, bottom: bottom, left: left, right: right, } end private def centre @_centre ||= Terminal.centre end def centre_y centre.first end def centre_x centre.last end def virtual_y @_virtual_y ||= (top..bottom).to_a end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.1.6 | lib/vedeu/models/geometry.rb |
vedeu-0.1.5 | lib/vedeu/models/geometry.rb |
vedeu-0.1.4 | lib/vedeu/models/geometry.rb |