Class: Reissue::Markdown::Change
- Inherits:
-
Object
- Object
- Reissue::Markdown::Change
- Defined in:
- lib/reissue/markdown.rb
Instance Method Summary collapse
-
#initialize(chunk) ⇒ Change
constructor
A new instance of Change.
- #parse ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(chunk) ⇒ Change
Returns a new instance of Change.
85 86 87 88 89 |
# File 'lib/reissue/markdown.rb', line 85 def initialize(chunk) @chunk = chunk @type = nil @changes = [] end |
Instance Method Details
#parse ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/reissue/markdown.rb', line 91 def parse return unless @type.nil? && @changes.empty? scanner = StringScanner.new(@chunk) << "\n" scanner.scan(/([\w\s]+)$/) @type = scanner[1].to_s.strip # the rest of the text are the changes @changes = scanner .rest .strip .split(/^-/m) .map { |change| change.strip.gsub(/^- /m, "") } .reject(&:empty?) end |
#to_h ⇒ Object
107 108 109 110 111 112 |
# File 'lib/reissue/markdown.rb', line 107 def to_h parse { @type => @changes.map { |change| change.split("\n").map(&:strip).join("\n ") } } end |