Class: Fitting::Documentation::Request::Route

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

Instance Method Summary collapse

Constructor Details

#initialize(response_routes) ⇒ Route

Returns a new instance of Route.



7
8
9
# File 'lib/fitting/documentation/request/route.rb', line 7

def initialize(response_routes)
  @response_routes = response_routes
end

Instance Method Details

#conformity_listsObject



95
96
97
98
99
100
101
102
# File 'lib/fitting/documentation/request/route.rb', line 95

def conformity_lists
  puts "Fully conforming requests: \n#{fully_implemented.join("\n")}"
  puts
  puts "Partially conforming requests: \n#{partially_implemented.join("\n")}"
  puts
  puts "Non-conforming requests: \n#{no_implemented.join("\n")}"
  puts
end

#coverage_statisticObject



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
62
# File 'lib/fitting/documentation/request/route.rb', line 11

def coverage_statistic
  stat = {}
  @response_routes.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
  @response_routes.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



68
69
70
71
72
73
74
75
# File 'lib/fitting/documentation/request/route.rb', line 68

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



86
87
88
89
90
91
92
93
# File 'lib/fitting/documentation/request/route.rb', line 86

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



77
78
79
80
81
82
83
84
# File 'lib/fitting/documentation/request/route.rb', line 77

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



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fitting/documentation/request/route.rb', line 104

def statistics
  full_count = to_hash['full cover'].size
  part_count = to_hash['partial cover'].size
  no_count = 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)
  puts "API requests with fully implemented responses: #{full_count} (#{full_percentage}% of #{total_count})."
  puts "API requests with partially implemented responses: #{part_count} (#{part_percentage}% of #{total_count})."
  puts "API requests with no implemented responses: #{no_count} (#{no_percentage}% of #{total_count})."
  puts
end

#to_hashObject



64
65
66
# File 'lib/fitting/documentation/request/route.rb', line 64

def to_hash
  @stat ||= coverage_statistic
end