Class: Gort::UserAgentRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/gort/user_agent_rule.rb

Overview

User-agent rule.

Instance Attribute Summary

Attributes inherited from Rule

#name, #value

Formatting Methods collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ UserAgentRule

Returns a new instance of UserAgentRule.



8
9
10
# File 'lib/gort/user_agent_rule.rb', line 8

def initialize(value)
  super(:"user-agent", value)
end

Instance Method Details

#inspectString

A human readable representation of the rule.

Returns:

  • (String)


34
35
36
# File 'lib/gort/user_agent_rule.rb', line 34

def inspect
  %(#<#{self.class.name}:#{object_id} "#{value}">)
end

#pretty_print(pp) ⇒ void

This method returns an undefined value.

Produces a pretty human readable representation of the rule.

Parameters:

  • pp (PrettyPrint)

    pretty printer



45
46
47
# File 'lib/gort/user_agent_rule.rb', line 45

def pretty_print(pp)
  pp.text("#{self.class.name}/#{object_id}< #{value} >")
end

#valid?Boolean

Returns true if the value is a valid user agent.

A user agent token is a sequence of letters (a—z, A—Z), digits (0—9), underscores (_), or hyphens (-). Alternatively, a single asterisk (*) is also allowed.

Returns:

  • (Boolean)
    • true if the value is a valid product token

    • false otherwise



23
24
25
# File 'lib/gort/user_agent_rule.rb', line 23

def valid?
  value.match?(PRODUCT_TOKEN_RE)
end