Class: Twiddler::Config::Chord

Inherits:
Object
  • Object
show all
Defined in:
lib/twiddler/config.rb

Direct Known Subclasses

KeyChord, MouseChord

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChord

Returns a new instance of Chord.



216
217
218
219
220
# File 'lib/twiddler/config.rb', line 216

def initialize
  @rows = [:open, :open, :open, :open]
  @mods = {:num => false, 
    :shift => false, :ctrl => false, :alt => false}
end

Instance Attribute Details

#modsObject (readonly)

Returns the value of attribute mods.



222
223
224
# File 'lib/twiddler/config.rb', line 222

def mods
  @mods
end

#rowsObject (readonly)

Returns the value of attribute rows.



222
223
224
# File 'lib/twiddler/config.rb', line 222

def rows
  @rows
end

Instance Method Details

#extract_key(bits, idx, mod, range) ⇒ Object



224
225
226
227
228
229
230
231
232
233
# File 'lib/twiddler/config.rb', line 224

def extract_key(bits, idx, mod, range)
  @rows[idx] = case bits[range]
               when /1.../; :left
               when /.1../; :middle
               when /..1./; :right
               else :open
               end
  @mods[mod] = (bits[range.last] == ?1)

end

#keydata=(bits) ⇒ Object



235
236
237
238
239
240
# File 'lib/twiddler/config.rb', line 235

def keydata=(bits)
  extract_key(bits, 0, :num,    4..7)
  extract_key(bits, 1, :alt,    0..3)
  extract_key(bits, 2, :ctrl,  12..15)
  extract_key(bits, 3, :shift,  8..11)
end

#renderObject



269
270
271
# File 'lib/twiddler/config.rb', line 269

def render
  "#{render_keys} => #{render_action}"
end

#render_actionObject



265
266
267
# File 'lib/twiddler/config.rb', line 265

def render_action
  ""
end

#render_keysObject



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/twiddler/config.rb', line 242

def render_keys
  mods = 
    (@mods[:num] ?   "N" : "") +
    (@mods[:alt] ?   "A" : "") +
    (@mods[:ctrl] ?  "C" : "") +
    (@mods[:shift] ? "S" : "")
  if mods.empty?
    mods = "O"
  end

  chord = rows.map do |row|
    case row
    when :open;   "O"
    when :left;   "L"
    when :right;  "R"
    when :middle; "M"
    else "wtf?"
    end
  end.join("")

  return "#{mods} #{chord}"
end