Class: Rack::Mount::Analysis::Frequency
- Inherits:
-
Object
- Object
- Rack::Mount::Analysis::Frequency
- Defined in:
- lib/rack/mount/analysis/frequency.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Method Summary collapse
- #<<(key) ⇒ Object
- #clear ⇒ Object
- #expire! ⇒ Object
-
#initialize(*keys) ⇒ Frequency
constructor
A new instance of Frequency.
- #possible_keys ⇒ Object
- #process_key(requirements, method, requirement) ⇒ Object
- #report ⇒ Object
Constructor Details
#initialize(*keys) ⇒ Frequency
Returns a new instance of Frequency.
6 7 8 9 |
# File 'lib/rack/mount/analysis/frequency.rb', line 6 def initialize(*keys) clear keys.each { |key| self << key } end |
Instance Method Details
#<<(key) ⇒ Object
17 18 19 20 21 |
# File 'lib/rack/mount/analysis/frequency.rb', line 17 def <<(key) raise ArgumentError unless key.is_a?(Hash) @raw_keys << key nil end |
#clear ⇒ Object
11 12 13 14 15 |
# File 'lib/rack/mount/analysis/frequency.rb', line 11 def clear @raw_keys = [] @key_frequency = Analysis::Histogram.new self end |
#expire! ⇒ Object
55 56 57 |
# File 'lib/rack/mount/analysis/frequency.rb', line 55 def expire! @possible_keys = @report = nil end |
#possible_keys ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/mount/analysis/frequency.rb', line 23 def possible_keys @possible_keys ||= begin @raw_keys.map do |key| key.inject({}) { |requirements, (method, requirement)| process_key(requirements, method, requirement) requirements } end end end |
#process_key(requirements, method, requirement) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rack/mount/analysis/frequency.rb', line 34 def process_key(requirements, method, requirement) if requirement.is_a?(Regexp) expression = Utils.parse_regexp(requirement) if expression.is_a?(Regin::Expression) && expression.anchored_to_line? expression = Regin::Expression.new(expression.reject { |e| e.is_a?(Regin::Anchor) }) return requirements[method] = expression.to_s if expression.literal? end end requirements[method] = requirement end |
#report ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rack/mount/analysis/frequency.rb', line 47 def report @report ||= begin possible_keys.each { |keys| keys.each_pair { |key, _| @key_frequency << key } } return [] if @key_frequency.count <= 1 @key_frequency.keys_in_upper_quartile end end |