class Stepmod::Utils::Converters::ExpressG

Public Instance Methods

convert(node, state = {}) click to toggle source
# File lib/stepmod/utils/converters/express_g.rb, line 7
def convert(node, state = {})
  node.children.map do |child|
    next unless child.name == "imgfile"

    parse_to_svg_reference(child["file"], state)
  end.join("\n")
end

Private Instance Methods

parse_to_svg_reference(file, state) click to toggle source
# File lib/stepmod/utils/converters/express_g.rb, line 17
        def parse_to_svg_reference(file, state)
          return "" unless File.file?(file)

          image_document = Nokogiri::XML(File.read(file))
          svg_path = File.basename(image_document.xpath("//img").first["src"],
                                   ".*")
          <<~SVGMAP

            *)
            (*"#{state.fetch(:schema_name)}.__expressg"
            [.svgmap]
            ====
            image::#{svg_path}.svg[]

            #{image_document.xpath('//img.area').map.with_index(1) { |n, i| schema_reference(n['href'], i) }.join("\n")}
            ====
          SVGMAP
        end
schema_reference(xml_path, index) click to toggle source
# File lib/stepmod/utils/converters/express_g.rb, line 36
def schema_reference(xml_path, index)
  if /#/.match?(xml_path)
    _, express_path_part = xml_path.split("#")
    "* <<express:#{express_path_part.strip}>>; #{index}"
  else
    schema_name = File.basename(xml_path, ".*")
    "* <<express:#{schema_name.strip}>>; #{index}"
  end
end