Class: NTYChangeLog::Parser
- Inherits:
-
Object
- Object
- NTYChangeLog::Parser
- Defined in:
- lib/nty_change_log/parser.rb
Instance Method Summary collapse
- #parse(text) ⇒ Object
- #parse_change_groups(text) ⇒ Object
- #parse_changes(text) ⇒ Object
- #parse_versions(text) ⇒ Object
Instance Method Details
#parse(text) ⇒ Object
3 4 5 6 |
# File 'lib/nty_change_log/parser.rb', line 3 def parse(text) versions = parse_versions(text.strip) ChangeLog.new(versions) end |
#parse_change_groups(text) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/nty_change_log/parser.rb', line 17 def parse_change_groups(text) return [] if text.empty? result = text.split(/^### (.+)$/)[1..-1].map(&:strip) Hash[*result].map do |name, change_texts| changes = parse_changes(change_texts) ChangeGroup.new(name, changes) end end |
#parse_changes(text) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nty_change_log/parser.rb', line 26 def parse_changes(text) return [] if text.empty? rows = text.split("\n").map(&:strip) rows.map do |row| if match = row.match(/\[#(?<number>\d+)\]\((?<url>\S+)\)/) issue = Issue.new(match[:number].to_i, match[:url]) description = row.gsub(/\*\s*(.+)\s+\[#\d+\]\(\S+\)$/) { $1 } Change.new(description, issue) else description = row.gsub(/\*\s*(.+)$/) { $1 } Change.new(description, nil) end end end |
#parse_versions(text) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/nty_change_log/parser.rb', line 8 def parse_versions(text) return [] if text.empty? result = text.split(/^## (.+)$/)[1..-1].map(&:strip) Hash[*result].map do |name, change_group_texts| change_groups = parse_change_groups(change_group_texts) Version.new(name, change_groups) end end |