class UpdateDraftRelease::Content
Constants
- HEADING_REGEX
Attributes
body[R]
line_separator[R]
lines[R]
Public Class Methods
new(body)
click to toggle source
# File lib/content.rb, line 7 def initialize(body) @body = body @line_separator = if body =~ /(\r\n|\n)/ then $1 else %(\r\n) end @lines = body.split(@line_separator) end
Public Instance Methods
append(new_lines)
click to toggle source
# File lib/content.rb, line 29 def append(new_lines) insert(@lines.size, new_lines) end
find_heading(heading)
click to toggle source
# File lib/content.rb, line 25 def find_heading(heading) @lines.index { |line| line.match(/^\s*#+\s+.*#{heading}.*/i) } end
heading_indexes()
click to toggle source
# File lib/content.rb, line 21 def heading_indexes @lines.each_index.select { |i| @lines[i].match(HEADING_REGEX) } end
headings()
click to toggle source
# File lib/content.rb, line 17 def headings @lines.select { |line| line.match(HEADING_REGEX) } end
include?(sha)
click to toggle source
# File lib/content.rb, line 41 def include?(sha) @body.include?(sha) end
insert(line_num, new_lines)
click to toggle source
# File lib/content.rb, line 33 def insert(line_num, new_lines) if line_num == 0 || @lines[line_num - 1].strip.empty? @lines[line_num,0] = Array(new_lines).flat_map { |line| [line, ''] } else @lines[line_num,0] = Array(new_lines).flat_map { |line| ['', line] } end end
title()
click to toggle source
# File lib/content.rb, line 13 def title @lines.first[0].upcase + @lines.first[1..-1] end
to_s()
click to toggle source
# File lib/content.rb, line 45 def to_s @lines.join(@line_separator) end