class Epuber::Epubcheck
Constants
- Problem
- Report
Public Class Methods
Source
# File lib/epuber/epubcheck.rb, line 65 def _parse_json(string) json = JSON.parse(string) messages = json['messages'] problems = messages .map { |msg| _parse_locations(msg) } .flatten Report.new(problems: problems) end
Parse json from epubcheck
@param [String] string json string @return [Report]
Source
# File lib/epuber/epubcheck.rb, line 80 def _parse_locations(json) json['locations'].map do |json_location| location = Epuber::Location.new( path: json_location['path'], lineno: json_location['line'], column: json_location['column'], ) Problem.new( level: json['severity'].downcase.to_sym, code: json['ID'], message: json['message'], location: location, ) end end
Parse all problems from single message
@param [Hash] json @return [Array<Problem>]
Source
# File lib/epuber/epubcheck.rb, line 46 def check(path) report = nil Dir.mktmpdir('epubcheck-') do |tmpdir| json_path = File.join(tmpdir, 'epubcheck.json') Open3.popen3('epubcheck', path, '--json', json_path) do |_in, _out, _err, wait_thr| wait_thr.value # wait for the process to finish report = _parse_json(File.read(json_path)) end end report end
@param [String] path path to file
@return [Report] report of the epubcheck