Class: WorkingSetItem

Inherits:
Object show all
Defined in:
lib/working_set_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(props = {}) ⇒ WorkingSetItem

Returns a new instance of WorkingSetItem.



4
5
6
7
8
9
10
11
12
# File 'lib/working_set_item.rb', line 4

def initialize(props = {})
  self.file_path        = props[:file_path]
  self.row              = (props[:row]             || 0).to_i
  self.column           = (props[:column]          || 0).to_i
  self.pre_match_lines  = props[:pre_match_lines]  || []
  self.match_line       = props[:match_line]       || ""
  self.post_match_lines = props[:post_match_lines] || []
  self.pinned           = !!props[:pinned]
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



2
3
4
# File 'lib/working_set_item.rb', line 2

def column
  @column
end

#file_pathObject

Returns the value of attribute file_path.



2
3
4
# File 'lib/working_set_item.rb', line 2

def file_path
  @file_path
end

#match_lineObject

Returns the value of attribute match_line.



2
3
4
# File 'lib/working_set_item.rb', line 2

def match_line
  @match_line
end

#pinnedObject

Returns the value of attribute pinned.



2
3
4
# File 'lib/working_set_item.rb', line 2

def pinned
  @pinned
end

#post_match_linesObject

Returns the value of attribute post_match_lines.



2
3
4
# File 'lib/working_set_item.rb', line 2

def post_match_lines
  @post_match_lines
end

#pre_match_linesObject

Returns the value of attribute pre_match_lines.



2
3
4
# File 'lib/working_set_item.rb', line 2

def pre_match_lines
  @pre_match_lines
end

#rowObject

Returns the value of attribute row.



2
3
4
# File 'lib/working_set_item.rb', line 2

def row
  @row
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/working_set_item.rb', line 28

def ==(other)
  other &&
    file_path == other.file_path &&
    row == other.row &&
    column == other.column &&
    match_line == other.match_line
end

#full_bodyObject



36
37
38
# File 'lib/working_set_item.rb', line 36

def full_body
  (pre_match_lines + [match_line] + post_match_lines).join("\n")
end

#inspectObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/working_set_item.rb', line 14

def inspect
  str = "#{file_path}\n"
  pre_match_lines.each_with_index do |line, idx|
    str += "#{row - pre_match_lines.size + idx}- #{line}\n"
  end
  str += "#{row}: #{match_line}\n"
  offset = column + row.to_s.length + 1
  str += sprintf "%#{offset}s%s", " ", "^\n"
  post_match_lines.each_with_index do |line, idx|
    str += "#{row + 1 + idx}- #{line}\n"
  end
  str
end