Sha256: 973a9c36ffef69b79a890f55a60048da18262115da6cfbd04009808f0e083b34

Contents?: true

Size: 732 Bytes

Versions: 1

Compression:

Stored size: 732 Bytes

Contents

# frozen_string_literal: true

class Mockolate::Request::Parser
  attr_reader :_attr_arr
  attr_reader :_export_key
  
  def initialize(attr_arr, options = {})
    @_attr_arr = attr_arr
    @_export_key  = options[:export_with]
  end

  def parse
    return _parse_to_hash if _export_key
    _parse_to_array
  end

  private
  def _parse_to_hash
    export_hash = {}
    _attr_arr.each do |attr|
      hash = {}
      attr.each do |t|
        hash.merge! t.parse
      end  
      export_hash[hash[_export_key]] = hash
    end
    return export_hash
  end

  def _parse_to_array
    _attr_arr.map do |attr|
      _hash = Hash.new
      
      attr.each do |t|
        _hash.merge! t.parse
      end  
      _hash
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mockolate-0.1.0 lib/mockolate/request/parser.rb