Class: MaimaiNet::Page::Base

Inherits:
Object
  • Object
show all
Extended by:
HelperSupport
Includes:
ModuleExt, ModuleExt::MethodCache
Defined in:
lib/maimai_net/page.rb,
lib/maimai_net/page-html_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HelperSupport

extended, helper_method, method_added

Methods included from ModuleExt::MethodCache

included, #singleton_method_added

Methods included from ModuleExt::HaveClassMethods

#class_method, #included

Constructor Details

#initialize(document) ⇒ Base

Returns a new instance of Base.

Parameters:

  • document (Nokogiri::HTML::Document)

Raises:

  • (ArgumentError)

    invalid document structure

See Also:



16
17
18
19
20
21
22
# File 'lib/maimai_net/page.rb', line 16

def initialize(document)
  @document = document
  @root = document.at_css('.main_wrapper')

  initialize_extension
  validate!
end

Class Method Details

.parse(content) ⇒ Page::Base

Parameters:

  • content (String)

    provided page content

Returns:



39
40
41
42
43
# File 'lib/maimai_net/page.rb', line 39

def parse(content)
  doc_class = Nokogiri::HTML
  doc_class = Nokogiri::HTML5 if defined?(Nokogiri::HTML5) && %r{^\s*<!DOCTYPE\s+html>\s?}i.match?(content)
  new(doc_class.parse(content))
end

Instance Method Details

#validate!void

This method returns an undefined value.

validates document structure

Raises:

  • (ArgumentError)

    invalid document structure



32
33
34
# File 'lib/maimai_net/page.rb', line 32

def validate!
  fail ArgumentError, 'provided document is not a valid maimai-net format' if @root.nil?
end