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.



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

def initialize(str = '')
  @changelogs = str.empty? ? {} : nil
  version = nil
  str.each_line do |line|
    line.rstrip!
    if /^Port Notes:$/ === line
      @changelogs = {}
    else
      unless @changelogs.nil?
        if match_data = /^----- version (.+) -----$/.match(line)
          version = match_data[1].intern
        else
          if match_data = /^(.+)$/.match(line)
            raise ReadmeSyntaxError, 'Version missing' if version.nil?
            if @changelogs.key?(version)
              @changelogs[version] << $INPUT_RECORD_SEPARATOR << match_data[1]
            else
              @changelogs[version] = match_data[1]
            end
          end
        end
      end
    end
  end
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
# File 'lib/xezat/cygchangelog.rb', line 34

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

#[]=(key, value) ⇒ Object



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

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

#eachObject



46
47
48
49
50
51
52
# File 'lib/xezat/cygchangelog.rb', line 46

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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