Sha256: f19f5e56059e1be88a766893a3e2579052cf482c12a9d0a4fab8d49b087273ad

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require 'xezat/cygversion'

module Xezat
  class ReadmeSyntaxError < StandardError
  end

  class Cygchangelog
    def initialize(str = '')
      @changelogs = nil
      version = nil
      str.each_line do |line|
        line.rstrip!
        if line == 'Port Notes:'
          @changelogs = {}
          next
        end
        next if @changelogs.nil?

        matched_version = /^----- version (.+) -----$/.match(line)
        if matched_version
          version = matched_version[1].intern
          next
        end
        matched_content = /^(.+)$/.match(line)
        next unless matched_content
        raise ReadmeSyntaxError, 'Version missing' if version.nil?

        if @changelogs.key?(version)
          @changelogs[version] << $INPUT_RECORD_SEPARATOR << matched_content[1]
        else
          @changelogs[version] = matched_content[1]
        end
      end
      @changelogs ||= {}
    end

    def [](key)
      @changelogs[key]
    end

    def []=(key, value)
      @changelogs[key] = value
    end

    def key?(key)
      @changelogs.key?(key)
    end

    def each
      logs = @changelogs.sort do |a, b|
        -(Cygversion.new(a[0].to_s) <=> Cygversion.new(b[0].to_s))
      end
      logs.each do |k, v|
        yield(k, v)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xezat-0.2.0 lib/xezat/cygchangelog.rb
xezat-0.1.2 lib/xezat/cygchangelog.rb