Class: Hypermicrodata::Extract

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

Instance Method Summary collapse

Constructor Details

#initialize(html, options = {}) ⇒ Extract

Returns a new instance of Extract.



3
4
5
6
7
8
9
# File 'lib/hypermicrodata/extract.rb', line 3

def initialize(html, options = {})
  default_data_attr_name = 'main-item'
  @location = options[:location]
  @profile_path = options[:profile_path]
  filter_xpath_attr = "@data-#{options[:data_attr_name] || default_data_attr_name}"
  @document = Hypermicrodata::Document.new(html, page_url: @location, filter_xpath_attr: filter_xpath_attr)
end

Instance Method Details

#to_json(format = :plain, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/hypermicrodata/extract.rb', line 11

def to_json(format = :plain, options = {})
  case format
  when :hal
    Hypermicrodata::Serializer::Hal.new(@document, @location, @profile_path).to_json(options)
  when :uber
    Hypermicrodata::Serializer::Uber.new(@document, @location, @profile_path).to_json(options)
  else
    Hypermicrodata::Serializer::Base.new(@document, @location, @profile_path).to_json(options)
  end
end