From 736e4d179be34d65750a1b6a3e1f0ee1610d494b Mon Sep 17 00:00:00 2001 From: Richard Ramsden Date: Sat, 19 May 2012 13:14:47 -0700 Subject: [PATCH] use OpenStruct instead of returning a hash value When we created a Packet object before using Packet.read would return a hash. Instead, return an OpenStruct object which makes accessing parameters easier --- lib/X11/display.rb | 3 ++- lib/X11/packet.rb | 4 +--- lib/X11/screen.rb | 8 ++++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/X11/display.rb b/lib/X11/display.rb index 8e7af53..bc06524 100644 --- a/lib/X11/display.rb +++ b/lib/X11/display.rb @@ -5,6 +5,7 @@ module X11 class AuthorizationError < X11Error; end class Display + attr_accessor :socket # Open a connection to the specified display (numbered from 0) on the specified host def initialize(target = ENV['DISPLAY']) @@ -25,7 +26,7 @@ module X11 end def screens - @internal[:screens].map do |s| + @internal.screens.map do |s| Screen.new(self, s) end end diff --git a/lib/X11/packet.rb b/lib/X11/packet.rb index 7e079cb..9d7dce4 100644 --- a/lib/X11/packet.rb +++ b/lib/X11/packet.rb @@ -50,7 +50,7 @@ module X11 end end - values + OpenStruct.new(values) end def field(*args) @@ -92,9 +92,7 @@ module X11 s.type == :unused or s.type == :length end end - end end - end end diff --git a/lib/X11/screen.rb b/lib/X11/screen.rb index 1efefcc..d0fecdf 100644 --- a/lib/X11/screen.rb +++ b/lib/X11/screen.rb @@ -8,11 +8,15 @@ module X11 end def width - @internal[:width_in_pixels] + @internal.width_in_pixels end def height - @internal[:height_in_pixels] + @internal.height_in_pixels + end + + def to_s + "#" end end end