Class: Twiddler::TargetBuilder::Flow

Inherits:
RegexpBuilder show all
Defined in:
lib/twiddler/target_builder.rb

Instance Method Summary collapse

Methods inherited from RegexpBuilder

#go, #match_any_of

Methods inherited from Builder

#go, #initialize, #output_to, register, registered

Constructor Details

This class inherits a constructor from Twiddler::TargetBuilder::Builder

Instance Method Details

#filenameObject



88
89
90
# File 'lib/twiddler/target_builder.rb', line 88

def filename
  "Flow"
end

#regexpObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/twiddler/target_builder.rb', line 92

def regexp
  flow = []
  chords = @config.keyboard.find_all do |chord|
    chord.single? and chord.keystrokes[0][1].empty? and Config.keytable.is_tagged?(chord.keystrokes[0][0], :letters)
  end

  chords.each do |first|
    chords.each do |second|
      next if first == second
      pairs = first.rows.zip(second.rows).find_all{|one,two| one != two}
      case pairs.length 
      when 1
        flow << first.render_action + second.render_action
        next
      when 2
        next if pairs.find{|pair| !pair.include?(:open)}
        if pairs[0][0] == pairs[1][1] and pairs[0][1] == pairs[1][0]
          flow << first.render_action + second.render_action
          next
        end
      end
    end
  end

  return %r{^.{0,1}(?:#{match_any_of(flow)}).{0,1}$}
end