<commit_before>require 'json'

module ContinuusLenimentus
  class Adapter
    def initialize(result)
      @result = result
    end

    def as_user
      encrypt? ? as_json : as_hash
    end

    def as_json
      as_hash.to_json
    end

    def as_hash
      {
        created_at: result.created_at,
        duration: rspec.fetch(:duration),
        counts: rspec.fetch(:counts),
        metrics: metrics
      }
    end

    private
    attr_reader :result

    def rspec
      ContinuusLenimentus::Runner.rspec.results
    end

    def metrics
      {
        total_lines: result.total_lines,
        coverage: coverage
      }
    end

    def coverage
      {
        percent: result.covered_percent,
        strength: strength,
        lines: result.covered_lines,
      }
    end

    def strength
      result.covered_strength.nan? ? 0.0 : result.covered_strength
    end<commit_msg>Default duration and count keys in adapter<commit_after>require 'json'

module ContinuusLenimentus
  class Adapter
    def initialize(result)
      @result = result
    end

    def as_user
      encrypt? ? as_json : as_hash
    end

    def as_json
      as_hash.to_json
    end

    def as_hash
      {
        created_at: result.created_at,
        duration: rspec.fetch(:duration, 0),
        counts: rspec.fetch(:counts, {}),
        metrics: metrics
      }
    end

    private
    attr_reader :result

    def rspec
      ContinuusLenimentus::Runner.rspec.results
    end

    def metrics
      {
        total_lines: result.total_lines,
        coverage: coverage
      }
    end

    def coverage
      {
        percent: result.covered_percent,
        strength: strength,
        lines: result.covered_lines,
      }
    end

    def strength
      result.covered_strength.nan? ? 0.0 : result.covered_strength
    end
{'fraction_non_alphanumeric': 0.06695938529088913, 'fraction_numerical': 0.0027442371020856204, 'mean_word_length': 1.9450726978998385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5507422', 'n_tokens_mistral': 566, 'n_tokens_neox': 546, 'n_words': 128}