Module: StringStubber::CoreExt
- Includes:
- Base
- Included in:
- String
- Defined in:
- lib/string_stubber/core_ext.rb
Constant Summary
Constants included
from Base
Base::SNIP, Base::WORD
Instance Method Summary
collapse
Methods included from Base
#scan_text, #scan_word, #scan_words
Instance Method Details
#scanner ⇒ Object
5
6
7
|
# File 'lib/string_stubber/core_ext.rb', line 5
def scanner
@scanner ||= StringScanner.new(self)
end
|
#stub_at_least(min_chars, save_pos = true) ⇒ Object
Also known as:
stub_thru, stub_through
35
36
37
38
39
40
41
42
43
|
# File 'lib/string_stubber/core_ext.rb', line 35
def stub_at_least(min_chars, save_pos=true)
scanner.reset unless save_pos
if min_chars < 0
rev_stub_at_least(min_chars.abs, save_pos)
else
scan_text(scanner, min_chars) << scan_word(scanner).to_s
end
end
|
#stub_at_most(max_chars, save_pos = true) ⇒ Object
Also known as:
stub_text, stub_chars, stub_pos, stub_to
21
22
23
24
25
26
27
28
29
|
# File 'lib/string_stubber/core_ext.rb', line 21
def stub_at_most(max_chars, save_pos=true)
scanner.reset unless save_pos
if max_chars < 0
rev_stub_at_most(max_chars.abs, save_pos)
else
scan_text(scanner, max_chars)
end
end
|
#stub_words(max_words, save_pos = false) ⇒ Object
Also known as:
stub, words
9
10
11
12
13
14
15
16
17
|
# File 'lib/string_stubber/core_ext.rb', line 9
def stub_words(max_words, save_pos=false)
scanner.reset unless save_pos
if max_words < 0
rev_stub_words(max_words.abs, save_pos)
else
scan_words(scanner, max_words)
end
end
|