Class: Xezat::Cygchangelog

Inherits:
Object
  • Object
show all
Defined in:
lib/xezat/cygchangelog.rb

Instance Method Summary collapse

Constructor Details

#initialize(str = '') ⇒ Cygchangelog

Returns a new instance of Cygchangelog.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/xezat/cygchangelog.rb', line 10

def initialize(str = '')
  @changelogs = nil
  version = nil
  str.each_line do |line|
    line.rstrip!
    if line == 'Port Notes:'
      @changelogs = {}
      next
    end
    next if @changelogs.nil?

    matched_version = /^----- version (.+) -----$/.match(line)
    if matched_version
      version = matched_version[1].intern
      next
    end
    matched_content = /^(.+)$/.match(line)
    next unless matched_content
    raise ReadmeSyntaxError, 'Version missing' if version.nil?

    if @changelogs.key?(version)
      @changelogs[version] << $INPUT_RECORD_SEPARATOR << matched_content[1]
    else
      @changelogs[version] = matched_content[1]
    end
  end
  @changelogs ||= {}
end

Instance Method Details

#[](key) ⇒ Object



39
40
41
# File 'lib/xezat/cygchangelog.rb', line 39

def [](key)
  @changelogs[key]
end

#[]=(key, value) ⇒ Object



43
44
45
# File 'lib/xezat/cygchangelog.rb', line 43

def []=(key, value)
  @changelogs[key] = value
end

#eachObject



51
52
53
54
55
56
57
58
# File 'lib/xezat/cygchangelog.rb', line 51

def each
  logs = @changelogs.sort do |a, b|
    -(Cygversion.new(a[0].to_s) <=> Cygversion.new(b[0].to_s))
  end
  logs.each do |k, v|
    yield(k, v)
  end
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/xezat/cygchangelog.rb', line 47

def key?(key)
  @changelogs.key?(key)
end