Class: Scrape::RobotsTxtRules

Inherits:
Object
  • Object
show all
Defined in:
lib/scrape/robots_txt_rules.rb

Instance Method Summary collapse

Constructor Details

#initialize(*rules) ⇒ RobotsTxtRules

Returns a new instance of RobotsTxtRules.



2
3
4
# File 'lib/scrape/robots_txt_rules.rb', line 2

def initialize *rules
  @rules = rules.flatten
end

Instance Method Details

#+(ary) ⇒ Object



11
12
13
# File 'lib/scrape/robots_txt_rules.rb', line 11

def + ary
  dup << ary.to_ary
end

#<<(rule) ⇒ Object



6
7
8
9
# File 'lib/scrape/robots_txt_rules.rb', line 6

def << rule
  @rules.push *Array(rule).flatten
  self
end

#=~(str) ⇒ Object



15
16
17
18
# File 'lib/scrape/robots_txt_rules.rb', line 15

def =~ str
  str = str.to_str
  @rules.any?{|rule| str.starts_with rule }
end

#to_aObject Also known as: to_ary



20
21
22
# File 'lib/scrape/robots_txt_rules.rb', line 20

def to_a
  @rules.dup
end