Class: Keystroker
- Inherits:
-
Object
- Object
- Keystroker
- Defined in:
- lib/keystroker.rb
Instance Method Summary collapse
-
#initialize(debug: false) ⇒ Keystroker
constructor
A new instance of Keystroker.
- #parse_hg0(s) ⇒ Object
- #to_hg0 ⇒ Object
- #to_kbml(options = {}) ⇒ Object
Constructor Details
#initialize(debug: false) ⇒ Keystroker
Returns a new instance of Keystroker.
22 23 24 |
# File 'lib/keystroker.rb', line 22 def initialize(debug: false) @debug = debug end |
Instance Method Details
#parse_hg0(s) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/keystroker.rb', line 26 def parse_hg0(s) xml = RexleBuilder.new a3 = xml.kbml do a = s.gsub(/\s*(?=\{)|(?<=\})\s*/,'').scan(/\{[^\}]+\}|./)\ .chunk {|x| x.length == 1}.map {|b, x| b ? x.join : x }.each do |x| if x.is_a? Array then x.each do |token| token[1..-2].split(/\s*[;,]\s*/).each do |instruction| puts ('instruction: ' + instruction.inspect).debug if @debug if instruction =~ /\*\s*\d+/ then key, n = instruction.split('*',2) #n.to_i.times {keypress(key, duration: duration) } xml.send(key.to_sym, {repeat: n}) else keys = instruction.split('+') if keys.length > 1 then name = keys[0..-2].join('_').to_sym xml.send(name, {key: keys.last}) else xml.send(instruction.to_sym) end end end end else xml.type x end end end @doc = Rexle.new(a3) end |
#to_hg0 ⇒ Object
76 77 |
# File 'lib/keystroker.rb', line 76 def to_hg0() end |
#to_kbml(options = {}) ⇒ Object
79 80 81 |
# File 'lib/keystroker.rb', line 79 def to_kbml(={}) @doc.xml() end |