Class: MobyCommand::KeySequence

Inherits:
CommandData show all
Defined in:
lib/tdriver/base/sut/generic/commands/key_sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CommandData

#get_application_id, #get_sut, #set_application_uid, #set_sut

Constructor Details

#initialize(key_symbol = nil, type_symbol = :ShortPress) ⇒ KeySequence

Constructor to KeySequence

params

key_symbol

(optional) Symbol of key to be added to sequence if given.

type_symbol

(optional) Symbol of keypress type of key if given, otherwise use default.

returns

Instance of KeySequence



32
33
34
35
36
37
# File 'lib/tdriver/base/sut/generic/commands/key_sequence.rb', line 32

def initialize( key_symbol = nil, type_symbol = :ShortPress )
	#TODO: Review comment (OR): @sequence -> @_sequence?
	@sequence = [] # Array.new( 0 )
	#@_sut = sut
	append!( key_symbol, type_symbol ) unless key_symbol.nil?
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



24
25
26
# File 'lib/tdriver/base/sut/generic/commands/key_sequence.rb', line 24

def id
  @id
end

Instance Method Details

#append!(key_symbol, type_symbol = :ShortPress) ⇒ Object

Function to append a keypress with type to KeySequence.sequence array

params

key_symbol

Symbol of key to be appended to sequence.

type_symbol

(optional) Symbol of keypress type of key if given, otherwise use default.

returns

self



45
46
47
48
# File 'lib/tdriver/base/sut/generic/commands/key_sequence.rb', line 45

def append!( key_symbol, type_symbol = :ShortPress )
	@sequence.push({:value => key_symbol, :type => type_symbol})    
	self       
end

#get_sequenceObject

Returns the stored sequence as an Array with Hash elements having :value and :type keys for each press.

returns

Array

Stored key sequence



85
86
87
# File 'lib/tdriver/base/sut/generic/commands/key_sequence.rb', line 85

def get_sequence
  @sequence
end

#times!(count = 1) ⇒ Object

Function to repeat last added keypress in sequence unless count is less than one or keypress sequence is empty

params

count

times of key repeated, default is one

returns

self

raises

TypeError

Wrong argument type <class> for times count (expected Fixnum)

ArgumentError

Positive value expected for times count (got <value>)

IndexError

Unable to multiply last given key due to key sequence is empty

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/tdriver/base/sut/generic/commands/key_sequence.rb', line 59

def times!( count = 1 )

    # verify count argument type
	#raise ArgumentError.new("Fixnum expected as argument") if count.class != Fixnum
    count.check_type( Fixnum, "Wrong argument type $1 for times count (expected $2)" )

    # verify that count is positive number
	raise ArgumentError.new( "Positive value expected for times count (got #{ count })" ) if count.negative?

    # verify that @sequence is not empty
	#raise IndexError.new( "Not allowed when empty key sequence" ) if @sequence.size == 0
	raise IndexError.new( "Unable to multiply last given key due to key sequence is empty" ) if @sequence.empty?

	count.times do | iteration |
	
		@sequence.push @sequence.fetch( -1 ) unless iteration == 0 

	end

	self
	
end