class Lighthouse::Ruby::Builder

Attributes

response[R]

Public Class Methods

new(url) click to toggle source
# File lib/lighthouse/ruby/builder.rb, line 10
def initialize(url)
  @url = url
  @runner = Lighthouse::Preferences.runner
  @cli = Lighthouse::Preferences.lighthouse_cli
  @port = Lighthouse::Preferences.remote_debugging_port
  @chrome_flags = Lighthouse::Preferences.chrome_flags
  @lighthouse_options = Lighthouse::Preferences.lighthouse_options
end

Public Instance Methods

execute() click to toggle source
# File lib/lighthouse/ruby/builder.rb, line 19
def execute
  @response = @runner.call("#{@cli} #{options}")
end
parsed_response() click to toggle source
# File lib/lighthouse/ruby/builder.rb, line 23
def parsed_response
  get_test_scores(JSON.parse(@response))
end

Private Instance Methods

get_test_scores(response) click to toggle source
# File lib/lighthouse/ruby/builder.rb, line 39
def get_test_scores(response)
  @test_scores = { url: @url}
  @test_scores[:run_time] = Time.now
  @test_scores[:performance] = response.dig("categories", "performance" , "score").to_f * 100
  @test_scores[:accessibility] = response.dig("categories", "accessibility" , "score").to_f * 100
  @test_scores[:best_practices] = response.dig("categories", "best-practices" , "score").to_f * 100
  @test_scores[:seo] = response.dig("categories", "seo" , "score").to_f * 100
  @test_scores
end
options() click to toggle source
# File lib/lighthouse/ruby/builder.rb, line 29
def options
  "'#{@url}'".tap do |builder|
    builder << ' --quiet'
    builder << ' --output=json'
    builder << " --port=#{@port}" if @port
    builder << " --#{@lighthouse_options}" if @lighthouse_options
    builder << " --chrome-flags='#{@chrome_flags}'" if @chrome_flags
  end.strip
end