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.
3 4 5 6 |
# File 'lib/fitting/documentation.rb', line 3 def initialize(tomogram, white_list) @tomogram = tomogram @white_list = white_list end |
Instance Method Details
#all ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fitting/documentation.rb', line 28 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
8 9 10 11 12 13 14 15 16 |
# File 'lib/fitting/documentation.rb', line 8 def black if @white_list all.select do |response| black?(response) end else [] end end |
#black?(response) ⇒ Boolean
46 47 48 49 |
# File 'lib/fitting/documentation.rb', line 46 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
39 40 41 42 43 44 |
# File 'lib/fitting/documentation.rb', line 39 def responses(request) request['responses'].each_with_object({}) do |response, responses| responses[response['status']] ||= 0 responses[response['status']] += 1 end end |
#white ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/fitting/documentation.rb', line 18 def white if @white_list all.select do |response| white?(response) end else all end end |
#white?(response) ⇒ Boolean
51 52 53 54 |
# File 'lib/fitting/documentation.rb', line 51 def white?(response) data = response.split(' ') data[1] && @white_list[data[1]] && (@white_list[data[1]] == [] || @white_list[data[1]].include?(data[0])) end |