Sha256: 50b714b2e668dff4e40f2c260faac31b121e2bfc275495a152b49e625e076180

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Quilt
  module Performance
    class Report
      attr_accessor :events
      attr_accessor :navigations
      attr_accessor :connection

      class << self
        def from_params(params)
          params.transform_keys! { |key| key.underscore.to_sym }
          params[:connection] = { effectiveType: 'unknown' } if params[:connection].blank?

          connection = Connection.from_params(params[:connection])

          Report.new(
            connection: connection,
            navigations: build_navigations(params[:navigations], connection: connection),
            events: build_events(params[:events], connection: connection),
          )
        end

        private

        def build_navigations(navigations_params, connection:)
          navigations_params ||= []
          navigations_params.map do |navigation|
            navigation = Navigation.from_params(navigation)
            navigation.connection = connection
            navigation
          end
        end

        def build_events(events_params, connection:)
          events_params ||= []
          events_params.map do |event|
            event = Event.from_params(event)
            event.connection = connection
            event
          end
        end
      end

      def initialize(events:, navigations:, connection:)
        @events = events
        @navigations = navigations
        @connection = connection
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
quilt_rails-3.5.5 lib/quilt_rails/performance/report.rb
quilt_rails-3.5.4 lib/quilt_rails/performance/report.rb
quilt_rails-3.5.2 lib/quilt_rails/performance/report.rb
quilt_rails-3.5.1 lib/quilt_rails/performance/report.rb
quilt_rails-3.5.0 lib/quilt_rails/performance/report.rb
quilt_rails-3.4.2 lib/quilt_rails/performance/report.rb
quilt_rails-3.4.1 lib/quilt_rails/performance/report.rb
quilt_rails-3.4.0 lib/quilt_rails/performance/report.rb
quilt_rails-3.3.1 lib/quilt_rails/performance/report.rb