class Morito::Processor

Public Class Methods

new(body) click to toggle source
# File lib/morito/processor.rb, line 3
def initialize(body)
  @body = body || ''
end

Public Instance Methods

allowed?(user_agent, path) click to toggle source
# File lib/morito/processor.rb, line 7
def allowed?(user_agent, path)
  UserAgentPermission.new(user_agent, whole_permission).allowed?(path)
end

Private Instance Methods

whole_permission() click to toggle source
# File lib/morito/processor.rb, line 13
def whole_permission
  return @whole_permission if @whole_permission

  @whole_permission = Hash.new {|h, k| h[k] = Hash.new {|h2, k2| h2[k2] = [] } }
  parser = LineParser.new

  @body.split(/\n+/).each do |line|
    parser.parse(line)
    if parser.disallow?
      @whole_permission[parser.user_agent][:disallow] << parser.disallow
    elsif parser.allow?
      @whole_permission[parser.user_agent][:allow] << parser.allow
    end
  end

  @whole_permission
end