Class: Vice::Movement

Inherits:
Object
  • Object
show all
Defined in:
lib/vice/movement.rb

Class Method Summary collapse

Class Method Details

.b(line, start) ⇒ Object



39
40
41
# File 'lib/vice/movement.rb', line 39

def self.b(line, start)
  b_real(line, start, false)
end

.b_internal(line, start, harsh) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/vice/movement.rb', line 24

def self.b_internal(line, start, harsh)
  return start if start.zero?

  return start if !whitespace(line[start], harsh) && whitespace(line[start - 1], harsh)

  b_internal(line, start - 1, harsh)
end

.b_large(line, start) ⇒ Object



43
44
45
# File 'lib/vice/movement.rb', line 43

def self.b_large(line, start)
  b_real(line, start, true)
end

.b_real(line, start, harsh) ⇒ Object



32
33
34
35
36
37
# File 'lib/vice/movement.rb', line 32

def self.b_real(line, start, harsh)
  # if we're already on the beginning of a word, we jump to the previous one
  start -= 1 if start > 0 && !whitespace(line[start], harsh) && whitespace(line[start - 1], harsh)

  b_internal(line, start, harsh)
end

.dollar(line) ⇒ Object



47
48
49
# File 'lib/vice/movement.rb', line 47

def self.dollar(line)
  line.length - 1
end

.w(line, start) ⇒ Object



16
17
18
# File 'lib/vice/movement.rb', line 16

def self.w(line, start)
  w_real(line, start, false)
end

.w_large(line, start) ⇒ Object



20
21
22
# File 'lib/vice/movement.rb', line 20

def self.w_large(line, start)
  w_real(line, start, true)
end

.w_real(line, start, harsh) ⇒ Object



10
11
12
13
14
# File 'lib/vice/movement.rb', line 10

def self.w_real(line, start, harsh)
  return start if start == line.length - 1
  return start + 1 if whitespace(line[start], harsh) && !whitespace(line[start + 1], harsh)
  w_real(line, start + 1, harsh)
end

.whitespace(char, harsh) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/vice/movement.rb', line 2

def self.whitespace(char, harsh)
  if harsh # only real whitespace
    (char == ' ' || char == "\t" || char == "\n")
  else # anything that's not alphanumeric
    char !~ /\A\p{Alnum}+\z/
  end
end

.zeroObject



51
52
53
# File 'lib/vice/movement.rb', line 51

def self.zero
  0
end