Class: Spacy::Text

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/spacy/text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = nil) ⇒ Text

Returns a new instance of Text.



21
22
23
24
# File 'lib/spacy/text.rb', line 21

def initialize (arg = nil)
  @buffer = (TextBuffer === arg) ? arg : TextBuffer.new(arg)
  @first = @last = 0
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



15
16
17
# File 'lib/spacy/text.rb', line 15

def buffer
  @buffer
end

Instance Method Details

#<<(str) ⇒ Object



90
91
92
# File 'lib/spacy/text.rb', line 90

def << (str)
  replace str, last
end

#columnObject



51
52
53
# File 'lib/spacy/text.rb', line 51

def column ()
  @buffer.pos2cursor(pos)[1]
end

#column=(n) ⇒ Object



59
60
61
# File 'lib/spacy/text.rb', line 59

def column= (n)
  self.cursor = row, n
end

#cursorObject



37
38
39
# File 'lib/spacy/text.rb', line 37

def cursor ()
  @buffer.pos2cursor pos
end

#cursor=(*args) ⇒ Object



41
42
43
44
45
# File 'lib/spacy/text.rb', line 41

def cursor= (*args)
  args.flatten!
  args << 0 while args.size < 2
  self.pos = @buffer.cursor2pos *args
end

#inspectObject



94
95
96
# File 'lib/spacy/text.rb', line 94

def inspect ()
  "#<Text row: #{row}, column: #{column}, buffer: #{buffer.inspect}>"
end

#posObject



26
27
28
# File 'lib/spacy/text.rb', line 26

def pos ()
  @first
end

#pos=(n) ⇒ Object



30
31
32
33
34
35
# File 'lib/spacy/text.rb', line 30

def pos= (n)
  last = @buffer.last
  n = 0    if n < 0
  n = last if n > last
  select n
end

#replace(str, first, last = nil) ⇒ Object



63
64
65
66
67
# File 'lib/spacy/text.rb', line 63

def replace (str, first, last = nil)
  last = first unless last
  @buffer.erase first, last
  @buffer.insert first, str
end

#rowObject



47
48
49
# File 'lib/spacy/text.rb', line 47

def row ()
  @buffer.pos2cursor(pos)[0]
end

#row=(n) ⇒ Object



55
56
57
# File 'lib/spacy/text.rb', line 55

def row= (n)
  self.cursor = n, column
end

#select(*args) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/spacy/text.rb', line 69

def select (*args)
  first, last = case args[0]
  when Range
    args[0].to_a
  when Integer
    args
  end
  last = first unless last
  first, last = last, first unless first < last
  @first, @last = first, last
  selection
end

#selectionObject



82
83
84
# File 'lib/spacy/text.rb', line 82

def selection ()
  @first..@last
end

#selection=(str) ⇒ Object



86
87
88
# File 'lib/spacy/text.rb', line 86

def selection= (str)
  select replace(str, @first, @last)
end