class SyncIssues::Parser
Synchronizer
is responsible for the actual synchronization.
Attributes
issue[R]
Public Class Methods
new(data)
click to toggle source
# File lib/sync_issues/parser.rb, line 10 def initialize(data) @issue = nil parse(data) end
Public Instance Methods
parse(data)
click to toggle source
# 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 (metadata = SafeYAML.load(Regexp.last_match(1))).nil? raise ParseError, 'empty frontmatter' else @issue = Issue.new content, **hash_keys_to_symbols(metadata) end rescue ArgumentError => exc raise ParseError, exc.message rescue Psych::SyntaxError raise ParseError, 'invalid frontmatter' end
Private Instance Methods
hash_keys_to_symbols(hash)
click to toggle source
# File lib/sync_issues/parser.rb, line 35 def hash_keys_to_symbols(hash) hash.each_with_object({}) do |(key, value), tmp_hash| tmp_hash[key.to_sym] = value end end