Class: VCLog::HistoryFile
- Inherits:
-
Object
- Object
- VCLog::HistoryFile
- Defined in:
- lib/vclog/history_file.rb
Overview
The HistoryFile class will parse a history into an array of release tags. Of course to do this, it assumes a specific file format.
Constant Summary collapse
- FILE =
'{HISTORY,HISTORY.*}'
- LINE =
/^[=#]/
- VERS =
/(\d+[._])+\d+/
- DATE =
/(\d+[-])+\d+/
- CASEFOLD =
Alias for ‘File::FNM_CASEFOLD`.
File::FNM_CASEFOLD
Instance Attribute Summary collapse
-
#tags ⇒ Object
readonly
Release tags.
Instance Method Summary collapse
-
#extract_tags ⇒ Object
Parse history file.
-
#initialize(source = nil) ⇒ HistoryFile
constructor
Setup new HistoryFile instance.
- #news ⇒ Object
Constructor Details
#initialize(source = nil) ⇒ HistoryFile
Setup new HistoryFile instance.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vclog/history_file.rb', line 22 def initialize(source=nil) if File.file?(source) @file = source @root = File.dirname(source) elsif File.directory?(source) @file = Dir.glob(File.join(source,FILE), CASEFOLD).first @root = source else @file = Dir.glob(FILE).first @root = Dir.pwd end raise "no history file" unless @file @tags = end |
Instance Attribute Details
#tags ⇒ Object (readonly)
Release tags.
19 20 21 |
# File 'lib/vclog/history_file.rb', line 19 def @tags end |
Instance Method Details
#extract_tags ⇒ Object
Parse history file.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vclog/history_file.rb', line 39 def = [] desc = '' text = File.read(@file) text.lines.each do |line| if LINE =~ line vers = (VERS.match(line) || [])[0] date = (DATE.match(line) || [])[0] next unless vers << [vers, date, desc = ''] else desc << line end end .map do |vers, date, desc| index = desc.index(/^Changes:/) || desc.index(/^\*/) || desc.size desc = desc[0...index].strip.fold #[vers, date, desc] Tag.new(:name=>vers, :date=>date, :msg=>desc) end end |
#news ⇒ Object
63 64 65 |
# File 'lib/vclog/history_file.rb', line 63 def news .first. end |