Class: Reissue::Markdown::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/reissue/markdown.rb

Instance Method Summary collapse

Constructor Details

#initialize(chunk) ⇒ Change

Returns a new instance of Change.



85
86
87
88
89
# File 'lib/reissue/markdown.rb', line 85

def initialize(chunk)
  @chunk = chunk
  @type = nil
  @changes = []
end

Instance Method Details

#parseObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/reissue/markdown.rb', line 91

def parse
  return unless @type.nil? && @changes.empty?
  scanner = StringScanner.new(@chunk) << "\n"
  scanner.scan(/([\w\s]+)$/)

  @type = scanner[1].to_s.strip

  # the rest of the text are the changes
  @changes = scanner
    .rest
    .strip
    .split(/^-/m)
    .map { |change| change.strip.gsub(/^- /m, "") }
    .reject(&:empty?)
end

#to_hObject



107
108
109
110
111
112
# File 'lib/reissue/markdown.rb', line 107

def to_h
  parse
  {
    @type => @changes.map { |change| change.split("\n").map(&:strip).join("\n  ") }
  }
end