Class: Reissue::Markdown::Version
- Inherits:
-
Object
- Object
- Reissue::Markdown::Version
- Defined in:
- lib/reissue/markdown.rb
Instance Method Summary collapse
-
#initialize(chunk) ⇒ Version
constructor
A new instance of Version.
- #parse ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(chunk) ⇒ Version
Returns a new instance of Version.
55 56 57 58 59 60 |
# File 'lib/reissue/markdown.rb', line 55 def initialize(chunk) @chunk = chunk @version = nil @date = nil @changes = [] end |
Instance Method Details
#parse ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/reissue/markdown.rb', line 62 def parse return unless @version.nil? && @date.nil? && @changes.empty? # the first line contains the version and date scanner = StringScanner.new(@chunk) << "\n" scanner.scan(/\[?(.[^\]]+)\]? - (.+)$/) @version = scanner[1].to_s.strip @date = scanner[2].to_s.strip || "Unreleased" # the rest of the text is the changes @changes = scanner.rest.strip.split("### ").reject(&:empty?).map { |change| Change.new(change) } end |
#to_h ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/reissue/markdown.rb', line 74 def to_h parse { "version" => @version, "date" => @date, "changes" => @changes.inject({}) { |h, change| h.merge(change.to_h) } } end |