Module: Hypermicrodata

Defined in:
lib/hypermicrodata.rb,
lib/hypermicrodata/item.rb,
lib/hypermicrodata/link.rb,
lib/hypermicrodata/extract.rb,
lib/hypermicrodata/version.rb,
lib/hypermicrodata/document.rb,
lib/hypermicrodata/property.rb,
lib/hypermicrodata/submit_button.rb,
lib/hypermicrodata/serializer/hal.rb,
lib/hypermicrodata/itemprop_parser.rb,
lib/hypermicrodata/serializer/base.rb,
lib/hypermicrodata/serializer/uber.rb,
lib/hypermicrodata/serializer/jsonld.rb,
lib/hypermicrodata/rails/html_based_json_renderer.rb

Defined Under Namespace

Modules: Rails, Serializer Classes: Document, Extract, FormItem, Item, ItempropParser, Link, Property, SubmitButton

Constant Summary collapse

VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.get_items(location, encoding = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/hypermicrodata.rb', line 24

def self.get_items(location, encoding = nil)
  f = open(location)
  page_url = location
  Hypermicrodata::Document.new(f, page_url: location, force_encoding: encoding).extract_items
ensure
  f.close
end

.to_json(location, encoding = nil) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/hypermicrodata.rb', line 32

def self.to_json(location, encoding = nil)
  items = get_items(location, encoding)
  hash = {}
  hash[:items] = items.map do |item|
    item.to_hash
  end
  JSON.pretty_generate hash
end