Class: Spacy::TextLine
- Inherits:
-
Object
- Object
- Spacy::TextLine
- Includes:
- Comparable
- Defined in:
- lib/spacy/textline.rb
Instance Method Summary collapse
- #<=>(obj) ⇒ Object
- #[](*args) ⇒ Object
- #[]=(*args) ⇒ Object
- #concat(str) ⇒ Object (also: #<<)
- #erase(first, last = nil) ⇒ Object
-
#initialize(str = nil) ⇒ TextLine
constructor
A new instance of TextLine.
- #insert(str, pos) ⇒ Object
- #inspect ⇒ Object
- #last ⇒ Object
- #ncolumn ⇒ Object
- #to_s ⇒ Object
- #to_textline ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ TextLine
Returns a new instance of TextLine.
11 12 13 14 |
# File 'lib/spacy/textline.rb', line 11 def initialize (str = nil) @str = '' insert str, 0 if str end |
Instance Method Details
#<=>(obj) ⇒ Object
62 63 64 |
# File 'lib/spacy/textline.rb', line 62 def <=> (obj) to_s <=> obj.to_s end |
#[](*args) ⇒ Object
54 55 56 |
# File 'lib/spacy/textline.rb', line 54 def [] (*args) @str.[](*args) end |
#[]=(*args) ⇒ Object
58 59 60 |
# File 'lib/spacy/textline.rb', line 58 def []= (*args) @str.[]=(*args) end |
#concat(str) ⇒ Object Also known as: <<
32 33 34 |
# File 'lib/spacy/textline.rb', line 32 def concat (str) insert str, last end |
#erase(first, last = nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/spacy/textline.rb', line 24 def erase (first, last = nil) last = first + 1 unless last first, last = last, first unless first < last raise RangeError unless 0 <= first && last <= self.last @str[first...last] = '' if first != last self end |
#insert(str, pos) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/spacy/textline.rb', line 16 def insert (str, pos) raise RangeError unless 0 <= pos && pos <= last str = str.to_s raise ArgumentError, "'str' has new-line char(s)." if str =~ /\r|\n/ @str.insert pos, str self end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/spacy/textline.rb', line 66 def inspect () "#<TextLine '#{@str}'>" end |
#last ⇒ Object
38 39 40 |
# File 'lib/spacy/textline.rb', line 38 def last () @str.size end |
#ncolumn ⇒ Object
42 43 44 |
# File 'lib/spacy/textline.rb', line 42 def ncolumn () last + 1 end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/spacy/textline.rb', line 46 def to_s () @str end |
#to_textline ⇒ Object
50 51 52 |
# File 'lib/spacy/textline.rb', line 50 def to_textline () self end |