Class: SyncIssues::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_issues/parser.rb

Overview

Synchronizer is responsible for the actual synchronization.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#issueObject (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.message
rescue Psych::SyntaxError
  raise ParseError, 'invalid frontmatter'
end