Sha256: 1df92201366f04b11bc31b4b9c33f3eb70d126d1c8fdadaf0f3bf469dab526df

Contents?: true

Size: 968 Bytes

Versions: 2

Compression:

Stored size: 968 Bytes

Contents

module Gametel
  module Views
    class View
      attr_reader :locator, :platform

      def initialize(platform, locator)
        @platform = platform
        @locator = locator
        build_property_methods
      end

      def view_class
        'android.view.View'
      end

      protected
      
      def properties
        [:clickable, :enabled, :focusable, :focused, :selected, :shown]
      end

      def build_property_methods
        metaclass = class << self; self; end
        properties.each do |property|
          metaclass.send(:define_method, "#{property}?".to_sym) do
            query_property = lambda {|device| device.send "is_#{property}" }
            platform.get_view_by_id(locator[:id], &query_property) if locator[:id]
            platform.get_view_by_index(view_class, locator[:index], &query_property) if locator[:index]
            platform.last_response.body == "true"
          end
        end
      end
      
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gametel-0.7 lib/gametel/views/view.rb
gametel-0.6 lib/gametel/views/view.rb