Class: CobwebModule::CrawlObject

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

Instance Method Summary collapse

Constructor Details

#initialize(content_hash, options = {}) ⇒ CrawlObject

Returns a new instance of CrawlObject.



4
5
6
7
# File 'lib/crawl_object.rb', line 4

def initialize(content_hash, options={})
  @content = HashUtil.deep_symbolize_keys(content_hash)
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/crawl_object.rb', line 18

def method_missing(m)
  if @content.keys.include? m.to_sym
    @content[m.to_sym]
  else
    super
  end
end

Instance Method Details

#permitted_type?Boolean

Helper method to determine if this content is to be processed or not

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/crawl_object.rb', line 11

def permitted_type?
  @options[:valid_mime_types].each do |valid_mime_type|
    return true if @content[:mime_type].match(Cobweb.escape_pattern_for_regex(valid_mime_type))
  end
  false
end

#to_hashObject



26
27
28
# File 'lib/crawl_object.rb', line 26

def to_hash
  @content
end