class ReleaseDove::Release

Constants

CHANGELOG
TAG

Attributes

content[R]
date[R]
header[R]
id[R]
version[R]

Public Class Methods

all() click to toggle source
# File lib/release_dove/release.rb, line 29
def all
  @all ||= releases.map { |*args| new(*args) }
end
count()
Alias for: size
find(id) click to toggle source
# File lib/release_dove/release.rb, line 45
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
first() click to toggle source
# File lib/release_dove/release.rb, line 37
def first
  all.last
end
last()
Alias for: take
length()
Alias for: size
new(id, content) click to toggle source
# File lib/release_dove/release.rb, line 9
def initialize(id, content)
  @id = id
  @content = content

  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
size() click to toggle source
# File lib/release_dove/release.rb, line 41
def size
  all.size
end
Also aliased as: count, length
take() click to toggle source
# File lib/release_dove/release.rb, line 33
def take
  all.first
end
Also aliased as: last

Private Class Methods

read_from_file() click to toggle source
# File lib/release_dove/release.rb, line 61
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
releases() { |id, content| ... } click to toggle source
# File lib/release_dove/release.rb, line 71
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

Public Instance Methods

==(other) click to toggle source
# File lib/release_dove/release.rb, line 24
def ==(other)
  id == other.id
end