Class: WordpressChangelog

Inherits:
Object
  • Object
show all
Defined in:
lib/reapack/index/parsers.rb

Constant Summary collapse

CHANGELOG =
/
  Changelog\s*:\n
  (.+?)\n\s*
  ((?:--)?\]\]|\*\/)
/xm.freeze
VERSION =
/\A[\s\*]*v([\d\.]+)(?:\s+(.+))?\Z/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(mh) ⇒ WordpressChangelog

Returns a new instance of WordpressChangelog.



10
11
12
# File 'lib/reapack/index/parsers.rb', line 10

def initialize(mh)
  @header = mh
end

Instance Method Details

#parse(input) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/reapack/index/parsers.rb', line 14

def parse(input)
  input.encode! Encoding::UTF_8, invalid: :replace

  ver, changes = @header[:version], @header[:changelog]
  return if ver.nil? || changes || CHANGELOG.match(input).nil?

  $1.lines.each {|line| read line.lstrip }
end

#read(line) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/reapack/index/parsers.rb', line 23

def read(line)
  if line =~ VERSION
    @current = $1 == @header[:version]
  elsif @current
    if @header[:changelog]
      @header[:changelog] += "\n"
    else
      @header[:changelog] = String.new
    end

    @header[:changelog] += line.chomp
  end
end