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



41
42
43
# File 'lib/vice/movement.rb', line 41

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



45
46
47
# File 'lib/vice/movement.rb', line 45

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

.b_real(line, start, harsh) ⇒ Object



32
33
34
35
36
37
38
39
# 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
	if start.positive? && !whitespace(line[start], harsh) && whitespace(line[start - 1], harsh)
		start -= 1
	end

	b_internal(line, start, harsh)
end

.dollar(line) ⇒ Object



49
50
51
# File 'lib/vice/movement.rb', line 49

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



53
54
55
# File 'lib/vice/movement.rb', line 53

def self.zero
	0
end