From 6e90225c9d74bd576d25ad00f9d5ee9ef5896851 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Thu, 16 Apr 2015 11:57:48 +0000 Subject: [PATCH] Add basic Client class --- lib/uh/wm.rb | 1 + lib/uh/wm/client.rb | 24 ++++++++++++++++++++++++ spec/uh/wm/client_spec.rb | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/uh/wm/client.rb create mode 100644 spec/uh/wm/client_spec.rb diff --git a/lib/uh/wm.rb b/lib/uh/wm.rb index 2bd157a..d259520 100644 --- a/lib/uh/wm.rb +++ b/lib/uh/wm.rb @@ -5,6 +5,7 @@ require 'uh' require 'uh/wm/actions_handler' require 'uh/wm/cli' +require 'uh/wm/client' require 'uh/wm/dispatcher' require 'uh/wm/env' require 'uh/wm/manager' diff --git a/lib/uh/wm/client.rb b/lib/uh/wm/client.rb new file mode 100644 index 0000000..546288d --- /dev/null +++ b/lib/uh/wm/client.rb @@ -0,0 +1,24 @@ +module Uh + module WM + class Client + attr_reader :window + + def initialize window, geo = nil + @window = window + @geo = geo + end + + def to_s + "<#{wname}> (#{wclass}) #{@geo} win: #{@window}" + end + + def wname + @wname ||= @window.name + end + + def wclass + @wclass ||= @window.wclass + end + end + end +end diff --git a/spec/uh/wm/client_spec.rb b/spec/uh/wm/client_spec.rb new file mode 100644 index 0000000..62cf8ef --- /dev/null +++ b/spec/uh/wm/client_spec.rb @@ -0,0 +1,39 @@ +module Uh + module WM + RSpec.describe Client do + let(:geo) { Geo.new(0, 0, 640, 480) } + let(:window) { double 'window', to_s: 'wid', name: 'wname', wclass: 'wclass' } + subject(:client) { described_class.new window, geo } + + describe '#to_s' do + it 'includes window name' do + expect(client.to_s).to include 'wname' + end + + it 'includes window class' do + expect(client.to_s).to include 'wclass' + end + + it 'includes geo' do + expect(client.to_s).to include geo.to_s + end + + it 'includes window id' do + expect(client.to_s).to include 'wid' + end + end + + describe '#wname' do + it 'returns the window name' do + expect(client.wname).to eq window.name + end + end + + describe '#wclass' do + it 'returns the window class' do + expect(client.wclass).to eq window.wclass + end + end + end + end +end