Class: Fitting::Documentation
- Inherits:
-
Object
- Object
- Fitting::Documentation
- Defined in:
- lib/fitting/documentation.rb
Instance Method Summary collapse
- #all ⇒ Object
- #black ⇒ Object
- #black?(response) ⇒ Boolean
-
#initialize(tomogram, white_list) ⇒ Documentation
constructor
A new instance of Documentation.
- #responses(request) ⇒ Object
- #white ⇒ Object
- #white?(response) ⇒ Boolean
Constructor Details
#initialize(tomogram, white_list) ⇒ Documentation
Returns a new instance of Documentation.
5 6 7 8 |
# File 'lib/fitting/documentation.rb', line 5 def initialize(tomogram, white_list) @tomogram = tomogram @white_list = white_list end |
Instance Method Details
#all ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fitting/documentation.rb', line 30 def all @all ||= @tomogram.to_hash.each_with_object([]) do |request, routes| responses(request).map do |status, indexes| indexes.times do |index| route = "#{request['method']}\t#{request['path']} #{status} #{index}" routes.push(route) end end end.uniq end |
#black ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/fitting/documentation.rb', line 10 def black if @white_list all.select do |response| black?(response) end else [] end end |
#black?(response) ⇒ Boolean
48 49 50 51 |
# File 'lib/fitting/documentation.rb', line 48 def black?(response) data = response.split(' ') data[1] && !@white_list[data[1]] || (@white_list[data[1]] != [] && !@white_list[data[1]].include?(data[0])) end |
#responses(request) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/fitting/documentation.rb', line 41 def responses(request) request['responses'].each_with_object({}) do |response, responses| responses[response['status']] ||= 0 responses[response['status']] += 1 end end |
#white ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/fitting/documentation.rb', line 20 def white if @white_list all.select do |response| white?(response) end else all end end |
#white?(response) ⇒ Boolean
53 54 55 56 |
# File 'lib/fitting/documentation.rb', line 53 def white?(response) data = response.split(' ') data[1] && @white_list[data[1]] && (@white_list[data[1]] == [] || @white_list[data[1]].include?(data[0])) end |