Class: Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/mark_set_go/comment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(init_line) ⇒ Comment

Returns a new instance of Comment.



4
5
6
7
# File 'lib/mark_set_go/comment.rb', line 4

def initialize(init_line)
  @lines = [init_line]
  set_type
end

Instance Attribute Details

#linesObject

Returns the value of attribute lines.



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

def lines
  @lines
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#remove_comment(line) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/mark_set_go/comment.rb', line 17

def remove_comment(line)
  if /^\/\//.match(line)
    line.gsub(/^\/\//, '')
  elsif /^\/\*/.match(line)
    line.gsub(/^\/\*/, '')
  else
    line
  end
end

#set_typeObject



9
10
11
12
13
14
15
# File 'lib/mark_set_go/comment.rb', line 9

def set_type
  if @lines.first.start_with? "/*"
    @type = "block"
  else
    @type = "line"
  end
end

#to_sObject



27
28
29
# File 'lib/mark_set_go/comment.rb', line 27

def to_s
  @lines.map { |line| remove_comment(line) }.join("")
end