Class: Fitting::Report::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/report/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
# File 'lib/fitting/report/response.rb', line 10

def initialize(response)
  @response = response
  @tests = Fitting::Report::Tests.new([])
  @id = SecureRandom.hex
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/fitting/report/response.rb', line 24

def id
  @id
end

#testsObject (readonly)

Returns the value of attribute tests.



24
25
26
# File 'lib/fitting/report/response.rb', line 24

def tests
  @tests
end

Instance Method Details

#add_test(test) ⇒ Object



26
27
28
# File 'lib/fitting/report/response.rb', line 26

def add_test(test)
  @tests.push(test)
end

#bodyObject



20
21
22
# File 'lib/fitting/report/response.rb', line 20

def body
  @response['body'] || @response[:body]
end

#combinationsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fitting/report/response.rb', line 30

def combinations
  return @combinations if @combinations

  cmbntns = []
  combinations = Fitting::Cover::JSONSchema.new(body).combi +
                 Fitting::Cover::JSONSchemaEnum.new(body).combi +
                 Fitting::Cover::JSONSchemaOneOf.new(body).combi
  if combinations != []
    combinations.map do |combination|
      cmbntns.push(
        Fitting::Report::Combination.new(
          json_schema: combination[0],
          type: combination[1][0],
          combination: combination[1][1]
        )
      )
    end
  end

  @combinations = Fitting::Report::Combinations.new(cmbntns)
end

#cover_percentObject



52
53
54
55
56
57
# File 'lib/fitting/report/response.rb', line 52

def cover_percent
  return '0%' if @tests.size.zero?
  return '100%' if @combinations.size.zero?

  "#{(@combinations.size_with_tests + 1) * 100 / (@combinations.size + 1)}%"
end

#detailsObject



59
60
61
62
63
64
65
66
67
# File 'lib/fitting/report/response.rb', line 59

def details
  {
    cover_percent: cover_percent,
    tests_without_combinations: @tests.without_combinations,
    combinations_details: @combinations.to_a.map do |c|
                            { json_schema: c.id, tests_size: c.tests.size, type: c.type, name: c.name }
                          end
  }
end

#statusObject



16
17
18
# File 'lib/fitting/report/response.rb', line 16

def status
  @response['status'] || @response[:status]
end