Sha256: e8af02a29f11c42ae8f87dff0bf374785ee916bf3f6a2748ad30fdf1ad535c0a

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "changelog_formatter/version"
require 'active_support/core_ext/object/blank'

class ChangelogFormatter

  CHANGELOG_ICONS = {
    new: 'plus',
    enh: 'wrench',
    fix: 'bug',
    del: 'minus',
  }

  attr :lines
  attr :name

  def initialize(name)
    @name  = name
    @lines = []
  end

  def self.to_a(changelog_file = 'CHANGELOG')
    releases = []
    release = ChangelogFormatter.new("Next Release")
    File.open(changelog_file) do |f|
      f.each_line do |line|
        if line =~ /^Release/
          releases << release unless release.lines.size == 0
          release = ChangelogFormatter.new(line.strip)
        else
          release.add_line(line) unless line.blank?
        end
      end
    end
    releases << release
  end

  def add_line(line)
    line = line.strip
    line =~ /^\[(.*)\] (.*)/
    if $1
      lines << [$1, $2]
    end
  end

  def date
    if name =~ / (\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/
      zone_total_offset = TZInfo::Timezone.get("Europe/Amsterdam").current_period.offset.utc_total_offset / 3600
      Time.new($1, $2, $3, $4, $5, 0, "+%02d:00" % zone_total_offset)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
changelog_formatter-0.0.1 lib/changelog_formatter.rb