Sha256: e6786f732cf8f9075f8c6c0169ef6d89a8db6b48aa83bdd3fe60bc98d22056ce

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

# Ruby internal
require 'json'

# TLS map module
module TLSmap
  # TLS mapping
  class App
    def markdown(table)
      output = "Codepoint | IANA | OpenSSL | GnuTLS | NSS\n"
      output += "--- | --- | --- | --- | ---\n"
      table.each do |alg|
        values = alg.values.map { |x| x.nil? ? '-' : x }
        output += "#{values.join(' | ')}\n"
      end
      output
    end

    def output_markdown(filename)
      File.write(filename, markdown(@tls_map))
    end

    def output_json_pretty(filename)
      File.write(filename, JSON.pretty_generate(@tls_map))
    end

    def output_json_compact(filename)
      File.write(filename, JSON.generate(@tls_map))
    end

    def output_marshal(filename)
      File.write(filename, Marshal.dump(@tls_map))
    end

    # Export the mapping to a file, supporting various formats.
    # @param filename [String] The output file name to write to.
    # @param format [Symbol] Supported formats: `:markdown` (a markdown table),
    #   `:json_pretty` (expanded JSON), `:json_compact` (minified JSON),
    #   `:marshal` (Ruby marshalized hash).
    def export(filename, format)
      case format
      when :markdown      then output_markdown(filename)
      when :json_pretty   then output_json_pretty(filename)
      when :json_compact  then output_json_compact(filename)
      when :marshal       then output_marshal(filename)
      else                     raise "Wrong format: #{format}"
      end
    end

    protected :markdown, :output_markdown, :output_json_pretty, :output_json_compact, :output_marshal
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tls-map-3.0.0 lib/tls_map/app/output.rb
tls-map-2.2.0 lib/tls_map/app/output.rb
tls-map-2.1.0 lib/tls_map/app/output.rb
tls-map-2.0.0 lib/tls_map/app/output.rb
tls-map-1.3.2 lib/tls_map/output.rb
tls-map-1.3.1 lib/tls_map/output.rb
tls-map-1.3.0 lib/tls_map/output.rb
tls-map-1.2.0 lib/tls_map/output.rb