Class: VCLog::HistoryFile

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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 = extract_tags
end

Instance Attribute Details

#tagsObject (readonly)

Release tags.



19
20
21
# File 'lib/vclog/history_file.rb', line 19

def tags
  @tags
end

Instance Method Details

#extract_tagsObject

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 extract_tags
  tags = []
  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
      tags << [vers, date, desc = '']
    else
      desc << line
    end
  end

  tags.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

#newsObject



63
64
65
# File 'lib/vclog/history_file.rb', line 63

def news
  tags.first.message
end