Class: Xezat::Cygchangelog
- Inherits:
-
Object
- Object
- Xezat::Cygchangelog
- Defined in:
- lib/xezat/cygchangelog.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #each ⇒ Object
-
#initialize(str = '') ⇒ Cygchangelog
constructor
A new instance of Cygchangelog.
- #key?(key) ⇒ Boolean
- #length ⇒ Object
Constructor Details
#initialize(str = '') ⇒ Cygchangelog
Returns a new instance of Cygchangelog.
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 38 |
# File 'lib/xezat/cygchangelog.rb', line 11 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 if matched_content.nil? 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
40 41 42 |
# File 'lib/xezat/cygchangelog.rb', line 40 def [](key) @changelogs[key] end |
#[]=(key, value) ⇒ Object
44 45 46 |
# File 'lib/xezat/cygchangelog.rb', line 44 def []=(key, value) @changelogs[key] = value end |
#each ⇒ Object
52 53 54 55 56 57 |
# File 'lib/xezat/cygchangelog.rb', line 52 def each(&) logs = @changelogs.sort do |a, b| -(Cygversion.new(a[0].to_s) <=> Cygversion.new(b[0].to_s)) end logs.each(&) end |
#key?(key) ⇒ Boolean
48 49 50 |
# File 'lib/xezat/cygchangelog.rb', line 48 def key?(key) @changelogs.key?(key) end |
#length ⇒ Object
59 60 61 |
# File 'lib/xezat/cygchangelog.rb', line 59 def length @changelogs.length end |