Class: Issuesrc::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/issuesrc/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, issue_id, author, title, file, line, begin_pos, end_pos) ⇒ Tag

Returns a new instance of Tag.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/issuesrc/tag.rb', line 12

def initialize(label, issue_id, author, title, file, line, 
               begin_pos, end_pos)
  @label = label
  @issue_id = issue_id.nil? || issue_id.empty? ? nil : issue_id
  @author = author.nil? || author.empty? ? nil : author
  @title = title
  @file = file
  @line = line
  @begin_pos = begin_pos
  @end_pos = end_pos
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



5
6
7
# File 'lib/issuesrc/tag.rb', line 5

def author
  @author
end

#begin_posObject (readonly)

Returns the value of attribute begin_pos.



9
10
11
# File 'lib/issuesrc/tag.rb', line 9

def begin_pos
  @begin_pos
end

#end_posObject (readonly)

Returns the value of attribute end_pos.



10
11
12
# File 'lib/issuesrc/tag.rb', line 10

def end_pos
  @end_pos
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/issuesrc/tag.rb', line 7

def file
  @file
end

#issue_idObject

Returns the value of attribute issue_id.



4
5
6
# File 'lib/issuesrc/tag.rb', line 4

def issue_id
  @issue_id
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/issuesrc/tag.rb', line 3

def label
  @label
end

#lineObject (readonly)

Returns the value of attribute line.



8
9
10
# File 'lib/issuesrc/tag.rb', line 8

def line
  @line
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/issuesrc/tag.rb', line 6

def title
  @title
end

Instance Method Details

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/issuesrc/tag.rb', line 24

def to_s
  ret = ""
  ret << @label
  if !@issue_id.nil? || !@author.nil?
    ret << '('
    if !@author.nil?
      ret << @author
    end
    if !@issue_id.nil?
      ret << '#' << @issue_id
    end
    ret << ')'
  end
  if !@title.nil?
    ret << ': ' << @title.strip
  end
  ret
end

#write_in_file(offsets) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/issuesrc/tag.rb', line 43

def write_in_file(offsets)
  total_offset = 0
  offsets.each do |pos, offset|
    if pos <= @begin_pos
      total_offset += offset
    end
  end
  old_begin_pos = @begin_pos
  @begin_pos += total_offset
  @end_pos += total_offset
  file.replace_at(@begin_pos, @end_pos-@begin_pos, to_s())
  new_end_pos = @begin_pos + to_s.length
  offset = new_end_pos - @end_pos
  @end_pos = new_end_pos
  offsets << [old_begin_pos, offset]
  offsets
end