Sha256: 186f54c9f38efbd16383a485710d9dbed1de323bd339f52966e2928c1d6f2b2d

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require 'slop'
require 'saxon-xslt'
require 'rumoji'

require_relative 'kaf_to_json/version'
require_relative 'kaf_to_json/server'
require_relative 'kaf_to_json/cli'

module Opener
  ##
  # Component for converting KAF documents to JSON objects.
  #
  class KafToJson
    ##
    # This method takes a single argument that is ignored to ensure
    # compatibility with all the other OpeNER components.
    #
    def initialize(*); end

    ##
    # Processes the input KAF document and returns a String containing the JSON
    # output.
    #
    # @param [String] input The input to process.
    # @return [String]
    #
    def run(input)
      encoded = Rumoji.encode(input)
      
      doc = Saxon::XML(encoded)
      
      xslt = Saxon::XSLT(File.read(xsl))
      
      decoded = Rumoji.decode(xslt.transform(doc).to_s)

      return decoded
    end

    alias tag run

    ##
    # The output type to use in the webservices.
    #
    # @return [Symbol]
    #
    def output_type
      return :json
    end

    private

    ##
    # @return [String]
    #
    def config_dir
      return File.expand_path('../../../config', __FILE__)
    end

    ##
    # @return [String]
    #
    def xsl
      return File.join(config_dir, 'kaf2json.xsl')
    end
  end # KafToJson
end # Opener

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opener-kaf2json-2.0.2-java lib/opener/kaf_to_json.rb
opener-kaf2json-2.0.1-java lib/opener/kaf_to_json.rb