Sha256: 8c658d4c07112643004e6221761ff9e881ab54fe68fef9ad6a807a5bd2bc294f
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
# frozen_string_literal: true require 'English' class ReleaseDove::Release attr_reader :id, :date, :version, :header, :content CHANGELOG = './CHANGELOG.md' TAG = /^.*(?<header>\[Unreleased\]|\[(?<version>\d+\.\d+\.\d+)\].*(?<date>\d{4}\-\d{2}\-\d{2}))$/i def initialize(id, content) @id = id @content = content assign_other_attributes end def assign_other_attributes return unless TAG =~ content @version = $LAST_MATCH_INFO[:version] @header = $LAST_MATCH_INFO[:header] @date = begin Date.parse $LAST_MATCH_INFO[:date].to_s rescue ArgumentError nil end end def ==(other) id == other.id end class << self def all @all ||= releases.map { |*args| new(*args) } end def take all.first end def first all.last end def size all.size end def find(id) id = id.to_i releases = all length = releases.length return unless (1..length).cover? id i = length - id releases.fetch(i) end alias count size alias length size alias last take private def releases return to_enum(:releases) unless block_given? log_content, log_indices = read_from_file log_indices.each_with_index do |pos, i| id = log_indices.size - i next_pos = log_indices[i + 1] || log_content.size content = log_content[pos, next_pos - pos] yield id, content end end def read_from_file file = File.open(CHANGELOG, 'rb', encoding: 'utf-8') content = file.read file.close indices = content.enum_for(:scan, TAG).map { Regexp.last_match.begin(0) } [content, indices] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
release_dove-0.2.0 | lib/release_dove/release.rb |