Class: ChangelogFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/changelog_formatter.rb,
lib/changelog_formatter/version.rb

Constant Summary collapse

CHANGELOG_ICONS =
{
  new: 'plus',
  enh: 'wrench',
  fix: 'bug',
  del: 'minus',
}
VERSION =
"0.0.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ChangelogFormatter

Returns a new instance of ChangelogFormatter.



16
17
18
19
# File 'lib/changelog_formatter.rb', line 16

def initialize(name)
  @name  = name
  @lines = []
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



13
14
15
# File 'lib/changelog_formatter.rb', line 13

def lines
  @lines
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/changelog_formatter.rb', line 14

def name
  @name
end

Class Method Details

.to_a(changelog_file = 'CHANGELOG') ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/changelog_formatter.rb', line 21

def self.to_a(changelog_file = 'CHANGELOG')
  releases = []
  release = ChangelogFormatter.new("Next Release")
  File.open(changelog_file) do |f|
    f.each_line do |line|
      if line =~ /^Release/
        releases << release unless release.lines.size == 0
        release = ChangelogFormatter.new(line.strip)
      else
        release.add_line(line) unless line.blank?
      end
    end
  end
  releases << release
end

Instance Method Details

#add_line(line) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/changelog_formatter.rb', line 37

def add_line(line)
  line = line.strip
  line =~ /^\[(.*)\] (.*)/
  if $1
    lines << [$1, $2]
  end
end

#dateObject



45
46
47
48
49
50
# File 'lib/changelog_formatter.rb', line 45

def date
  if name =~ / (\d{4})-(\d{2})-(\d{2})-(\d{2})(\d{2})/
    zone_total_offset = TZInfo::Timezone.get("Europe/Amsterdam").current_period.offset.utc_total_offset / 3600
    Time.new($1, $2, $3, $4, $5, 0, "+%02d:00" % zone_total_offset)
  end
end