Class: Issuesrc::Tag
- Inherits:
-
Object
- Object
- Issuesrc::Tag
- Defined in:
- lib/issuesrc/tag.rb
Overview
A tag is an annotation found in the source code of a file that holds information about the issue it corresponds to, the author or assignee, a label, a title for the isssue, and its position in the file.
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#begin_pos ⇒ Object
Returns the value of attribute begin_pos.
-
#end_pos ⇒ Object
Returns the value of attribute end_pos.
-
#file ⇒ Object
Returns the value of attribute file.
-
#issue_id ⇒ Object
Returns the value of attribute issue_id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#line ⇒ Object
Returns the value of attribute line.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(label, issue_id, author, title, file, line, begin_pos, end_pos) ⇒ Tag
constructor
A new instance of Tag.
-
#to_s ⇒ Object
The string representation of the tag, to be included in the source file.
-
#write_in_file(offsets) ⇒ Object
Writes the tag in its file, using its string representation.
Constructor Details
#initialize(label, issue_id, author, title, file, line, begin_pos, end_pos) ⇒ Tag
Returns a new instance of Tag.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/issuesrc/tag.rb', line 16 def initialize(label, issue_id, , title, file, line, begin_pos, end_pos) @label = label @issue_id = issue_id.nil? || issue_id.empty? ? nil : issue_id @author = .nil? || .empty? ? nil : @title = title @file = file @line = line @begin_pos = begin_pos @end_pos = end_pos end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
9 10 11 |
# File 'lib/issuesrc/tag.rb', line 9 def @author end |
#begin_pos ⇒ Object
Returns the value of attribute begin_pos.
13 14 15 |
# File 'lib/issuesrc/tag.rb', line 13 def begin_pos @begin_pos end |
#end_pos ⇒ Object
Returns the value of attribute end_pos.
14 15 16 |
# File 'lib/issuesrc/tag.rb', line 14 def end_pos @end_pos end |
#file ⇒ Object
Returns the value of attribute file.
11 12 13 |
# File 'lib/issuesrc/tag.rb', line 11 def file @file end |
#issue_id ⇒ Object
Returns the value of attribute issue_id.
8 9 10 |
# File 'lib/issuesrc/tag.rb', line 8 def issue_id @issue_id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/issuesrc/tag.rb', line 7 def label @label end |
#line ⇒ Object
Returns the value of attribute line.
12 13 14 |
# File 'lib/issuesrc/tag.rb', line 12 def line @line end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
10 11 12 |
# File 'lib/issuesrc/tag.rb', line 10 def title @title end |
Instance Method Details
#to_s ⇒ Object
The string representation of the tag, to be included in the source file.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/issuesrc/tag.rb', line 29 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
Writes the tag in its file, using its string representation.
Also updates the tag position information depending on offset
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/issuesrc/tag.rb', line 59 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 |