Class: Fitting::Route::Requests

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/route/requests.rb

Instance Method Summary collapse

Constructor Details

#initialize(coverage) ⇒ Requests

Returns a new instance of Requests.



6
7
8
# File 'lib/fitting/route/requests.rb', line 6

def initialize(coverage)
  @coverage = coverage
end

Instance Method Details

#conformity_listsObject



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fitting/route/requests.rb', line 111

def conformity_lists
  @stat ||= coverage_statistic
  fully_implemented ||= self.fully_implemented.join("\n")
  partially_implemented ||= self.partially_implemented.join("\n")
  no_implemented ||= self.no_implemented.join("\n")

  [
    ['Fully conforming requests:', fully_implemented].join("\n"),
    ['Partially conforming requests:', partially_implemented].join("\n"),
    ['Non-conforming requests:', no_implemented].join("\n")
  ].join("\n\n")
end

#coverage_statisticObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fitting/route/requests.rb', line 10

def coverage_statistic
  stat = {}
  @coverage.coverage.map do |route|
    macro_key = route.split(' ')[0..1].join(' ')
    micro_key = route.split(' ')[2..3].join(' ')
    stat[macro_key] ||= {}
    stat[macro_key]['cover'] ||= []
    stat[macro_key]['not_cover'] ||= []
    stat[macro_key]['cover'].push(micro_key)
    stat[macro_key]['all'] ||= []
    stat[macro_key]['all'].push("✔ #{route.split(' ')[2..3].join(' ')}")
  end
  @coverage.not_coverage.map do |route|
    macro_key = route.split(' ')[0..1].join(' ')
    micro_key = route.split(' ')[2..3].join(' ')
    stat[macro_key] ||= {}
    stat[macro_key]['cover'] ||= []
    stat[macro_key]['not_cover'] ||= []
    stat[macro_key]['not_cover'].push(micro_key)
    stat[macro_key]['all'] ||= []
    stat[macro_key]['all'].push("✖ #{route.split(' ')[2..3].join(' ')}")
  end
  @stat = stat.inject(
    {
      'full cover' => [],
      'partial cover' => [],
      'no cover' => []
    }
  ) do |res, date|
    ratio = date.last['cover_ratio'] =
      (date.last['cover'].size.to_f /
        (date.last['cover'].size + date.last['not_cover'].size).to_f * 100.0).round(2)
    info = {date.first => {
      'cover' => date.last['cover'],
      'not_cover' => date.last['not_cover'],
      'all' => "#{beautiful_output(date.last)}"
    }}
    if ratio == 100.0
      res['full cover'].push(info)
    elsif ratio == 0.0
      res['no cover'].push(info)
    else
      res['partial cover'].push(info)
    end
    path = date.first.split(' ')[1].size / 8
    @max ||= 1
    if path.size > @max
      @max = path.size
    end
    res
  end
end

#fully_implementedObject



67
68
69
70
71
72
73
74
# File 'lib/fitting/route/requests.rb', line 67

def fully_implemented
  @stat ||= coverage_statistic
  @fully_implemented ||= @stat['full cover'].map do |response|
    "#{response.first.to_a.first.split(' ').join("\t")}#{"\t"*(@max-response.first.to_a.first.split(' ')[1].size/8)}#{response.first.to_a.last['all']}"
  end.sort do |first, second|
    first.split("\t")[1] <=> second.split("\t")[1]
  end
end

#no_implementedObject



85
86
87
88
89
90
91
92
# File 'lib/fitting/route/requests.rb', line 85

def no_implemented
  @stat ||= coverage_statistic
  @no_implemented ||= @stat['no cover'].map do |response|
    "#{response.first.to_a.first.split(' ').join("\t")}#{"\t"*(@max-response.first.to_a.first.split(' ')[1].size/8)}#{response.first.to_a.last['all']}"
  end.sort do |first, second|
    first.split("\t")[1] <=> second.split("\t")[1]
  end
end

#partially_implementedObject



76
77
78
79
80
81
82
83
# File 'lib/fitting/route/requests.rb', line 76

def partially_implemented
  @stat ||= coverage_statistic
  @partially_implemented ||= @stat['partial cover'].map do |response|
    "#{response.first.to_a.first.split(' ').join("\t")}#{"\t"*(@max-response.first.to_a.first.split(' ')[1].size/8)}#{response.first.to_a.last['all']}"
  end.sort do |first, second|
    first.split("\t")[1] <=> second.split("\t")[1]
  end
end

#statisticsObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/fitting/route/requests.rb', line 94

def statistics
  @stat ||= coverage_statistic
  full_count = @stat.to_hash['full cover'].size
  part_count = @stat.to_hash['partial cover'].size
  no_count = @stat.to_hash['no cover'].size
  total_count = full_count + part_count + no_count
  full_percentage = (full_count.to_f / total_count.to_f * 100.0).round(2)
  part_percentage = (part_count.to_f / total_count.to_f * 100.0).round(2)
  no_percentage = (no_count.to_f / total_count.to_f * 100.0).round(2)

  [
    "API requests with fully implemented responses: #{full_count} (#{full_percentage}% of #{total_count}).",
    "API requests with partially implemented responses: #{part_count} (#{part_percentage}% of #{total_count}).",
    "API requests with no implemented responses: #{no_count} (#{no_percentage}% of #{total_count})."
  ].join("\n")
end

#to_hashObject



63
64
65
# File 'lib/fitting/route/requests.rb', line 63

def to_hash
  @stat ||= coverage_statistic
end