Class: SyncIssues::Parser
- Inherits:
-
Object
- Object
- SyncIssues::Parser
- Defined in:
- lib/sync_issues/parser.rb
Overview
Synchronizer is responsible for the actual synchronization.
Instance Attribute Summary collapse
-
#issue ⇒ Object
readonly
Returns the value of attribute issue.
Instance Method Summary collapse
-
#initialize(data) ⇒ Parser
constructor
A new instance of Parser.
- #parse(data) ⇒ Object
Constructor Details
#initialize(data) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 |
# File 'lib/sync_issues/parser.rb', line 10 def initialize(data) @issue = nil parse(data) end |
Instance Attribute Details
#issue ⇒ Object (readonly)
Returns the value of attribute issue.
8 9 10 |
# File 'lib/sync_issues/parser.rb', line 8 def issue @issue end |
Instance Method Details
#parse(data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sync_issues/parser.rb', line 15 def parse(data) unless data =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m raise ParseError, 'missing frontmatter' end if (content = $POSTMATCH).empty? raise ParseError, 'empty markdown content' elsif ( = SafeYAML.load(Regexp.last_match(1))).nil? raise ParseError, 'empty frontmatter' else @issue = Issue.new content, **hash_keys_to_symbols() end rescue ArgumentError => exc raise ParseError, exc. rescue Psych::SyntaxError raise ParseError, 'invalid frontmatter' end |