lib/release_dove/release.rb in release_dove-0.2.0 vs lib/release_dove/release.rb in release_dove-0.3.0
- old
+ new
@@ -2,20 +2,16 @@
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
+ TAG = /^.*(?<header>\[(?<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
@@ -60,10 +56,20 @@
alias length size
alias last take
private
+ 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
+
def releases
return to_enum(:releases) unless block_given?
log_content, log_indices = read_from_file
@@ -73,18 +79,8 @@
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