Sha256: ac5cd80ab446974c4501330650a42225788936f8dac265be1a56c86d83fad3f0
Contents?: true
Size: 962 Bytes
Versions: 9
Compression:
Stored size: 962 Bytes
Contents
module Tk class TkGeometry < Struct.new(:original, :width, :height, :x, :y) def initialize(tcl_string) case tcl_string.to_s when /^\=?(?<width>\d+)x(?<height>\d+)(?<x>[+-]\d+)(?<y>[+-]\d+)$/ md = $~ self.width, self.height, self.x, self.y = md[:width].to_i, md[:height].to_i, md[:x].to_i, md[:y].to_i when /^\=?(?<width>\d+)x(?<height>\d+)$/ md = $~ self.width, self.height = md[:width].to_i, md[:height].to_i when /^\=?(?<x>[+-]\d+)(?<y>[+-]\d+)$/ md = $~ self.x, self.y = md[:x].to_i, md[:y].to_i else raise "Invalid geometry: %p" % [tcl_string] end end def to_tcl if width && height && x && y "=%dx%d%+d%+d" % [width, height, x, y] elsif width && height "=%dx%d%" % [width, height] elsif x && y "=+d%+d" % [x, y] else raise "Incomplete geometry: %p" % [self] end end end end
Version data entries
9 entries across 9 versions & 1 rubygems