Class: Ruby::Node::Text::Clip

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/node/text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines, pos, length = nil) ⇒ Clip

Returns a new instance of Clip.



54
55
56
57
58
59
# File 'lib/ruby/node/text.rb', line 54

def initialize(lines, pos, length = nil)
  @lines = lines.is_a?(::String) ? Text.split(lines) : lines
  @row, @col = *pos
  @length = length.nil? ? self.lines.join.length : length
  init
end

Instance Attribute Details

#colObject (readonly)

Returns the value of attribute col.



52
53
54
# File 'lib/ruby/node/text.rb', line 52

def col
  @col
end

#endObject

Returns the value of attribute end.



52
53
54
# File 'lib/ruby/node/text.rb', line 52

def end
  @end
end

#lengthObject (readonly)

Returns the value of attribute length.



52
53
54
# File 'lib/ruby/node/text.rb', line 52

def length
  @length
end

#linesObject (readonly)

Returns the value of attribute lines.



52
53
54
# File 'lib/ruby/node/text.rb', line 52

def lines
  @lines
end

#rowObject (readonly)

Returns the value of attribute row.



52
53
54
# File 'lib/ruby/node/text.rb', line 52

def row
  @row
end

Instance Method Details

#headObject



69
70
71
# File 'lib/ruby/node/text.rb', line 69

def head
  lines[0, row].join + lines[row][0, col]
end

#srcObject



77
78
79
# File 'lib/ruby/node/text.rb', line 77

def src
  lines.join
end

#tailObject



73
74
75
# File 'lib/ruby/node/text.rb', line 73

def tail
  lines[self.end.row][self.end.col..-1] + lines[(self.end.row + 1)..-1].join
end

#to_sObject



81
82
83
# File 'lib/ruby/node/text.rb', line 81

def to_s
  @string
end