<commit_before># encoding: utf-8
require 'ruby-dmm/response/item'

module DMM
  class Response
    attr_reader :request, :result

    def initialize(response)
      @request = response[:request][:parameters][:parameter].inject({}) {|hash, params| hash.merge(params[:name].to_sym => params[:value]) }
      if response[:result][:message] && response[:result][:errors]
        @result  = response[:result]
      else
        @result  = DMM::Response::Result.new(response[:result])
      end
    end

    class Result
      RESULT_KEYS = [
        :first_position,
        :items,
        :result_count,
        :total_count,
      ]
      attr_reader *RESULT_KEYS

      def initialize(result)
        RESULT_KEYS.each do |key|
          case key
          when :items
            @items = [result[:items][:item]].flatten.map do |item|
              DMM::Response::Item.new(item)
            end if result.key?(:items)
            @items ||= []
          else
            instance_variable_set("@#{key}", result[key].to_i)
          end
        end
      end
    end
  end
end<commit_msg>Add alias method for `DMM::Result` class<commit_after># encoding: utf-8
require 'ruby-dmm/response/item'

module DMM
  class Response
    attr_reader :request, :result

    def initialize(response)
      @request = response[:request][:parameters][:parameter].inject({}) {|hash, params| hash.merge(params[:name].to_sym => params[:value]) }
      if response[:result][:message] && response[:result][:errors]
        @result  = response[:result]
      else
        @result  = DMM::Response::Result.new(response[:result])
      end
    end

    class Result
      RESULT_KEYS = [
        :first_position,
        :items,
        :result_count,
        :total_count,
      ]
      attr_reader *RESULT_KEYS
      alias_method :offset,     :first_position
      alias_method :per_result, :result_count

      def initialize(result)
        RESULT_KEYS.each do |key|
          case key
          when :items
            @items = [result[:items][:item]].flatten.map do |item|
              DMM::Response::Item.new(item)
            end if result.key?(:items)
            @items ||= []
          else
            instance_variable_set("@#{key}", result[key].to_i)
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1282163105102486, 'fraction_numerical': 0.0008722197993894462, 'mean_word_length': 2.230985915492958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1426936', 'n_tokens_mistral': 692, 'n_tokens_neox': 681, 'n_words': 142}