Class: SemanticCrawler::Websites::MicroData

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic_crawler/websites/micro_data.rb

Overview

Extract microdata from a website and output it as JSON

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ MicroData

Returns a new instance of MicroData.



12
13
14
15
16
17
# File 'lib/semantic_crawler/websites/micro_data.rb', line 12

def initialize(url)
  doc = Nokogiri::HTML(open(url))
  microdata = Microdata::Document.new(doc.to_s)
  items = microdata.extract_items
  self.microdata = extract_microdata(items)
end

Instance Attribute Details

#microdataObject

Returns the value of attribute microdata.



10
11
12
# File 'lib/semantic_crawler/websites/micro_data.rb', line 10

def microdata
  @microdata
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/semantic_crawler/websites/micro_data.rb', line 9

def url
  @url
end

Instance Method Details

#to_jsonObject



19
20
21
# File 'lib/semantic_crawler/websites/micro_data.rb', line 19

def to_json
  microdata.to_json
end

#to_sObject



23
24
25
# File 'lib/semantic_crawler/websites/micro_data.rb', line 23

def to_s
  microdata
end