Class: Gort::Group

Inherits:
RuleSet show all
Defined in:
lib/gort/group.rb

Overview

An access group

Instance Attribute Summary

Attributes inherited from RuleSet

#rules

Formatting Methods collapse

Instance Method Summary collapse

Methods inherited from RuleSet

#initialize, #merge

Constructor Details

This class inherits a constructor from Gort::RuleSet

Instance Method Details

#apply?(user_agent) ⇒ Boolean

Does this group apply to this specific user agent?

This performa user agent matcchign acording to the RFC.

Parameters:

  • user_agent (String)

Returns:

  • (Boolean)


25
26
27
# File 'lib/gort/group.rb', line 25

def apply?(user_agent)
  apply_to_all? || user_agent.match?(user_agent_regexp)
end

#inspectString

A human readable representation of the group.

Returns:

  • (String)


36
37
38
# File 'lib/gort/group.rb', line 36

def inspect
  "#<#{self.class.name}:#{object_id} #{rules.inspect}>"
end

#pretty_print(pp) ⇒ void

This method returns an undefined value.

Produces a pretty human readable representation of the group.

Parameters:

  • pp (PrettyPrint)

    pretty printer



47
48
49
50
51
52
53
54
55
56
# File 'lib/gort/group.rb', line 47

def pretty_print(pp)
  pp.text("#{self.class.name}/#{object_id}")
  pp.group(1, "[", "]") do
    pp.breakable("")
    pp.seplist(rules) do |rule|
      pp.pp(rule)
    end
    pp.breakable("")
  end
end

#valid?Boolean

Is this group valid?

A valid group has at least one valid user-agent rule.

Returns:

  • (Boolean)

See Also:



14
15
16
17
# File 'lib/gort/group.rb', line 14

def valid?
  @valid ||=
    rules.any? { |rule| rule.is_a?(UserAgentRule) && rule.valid? }
end