Class: Ducky::Sources::Core

Inherits:
Ducky::Source show all
Includes:
ERB::Util
Defined in:
lib/ducky/sources/core.rb

Direct Known Subclasses

StdLib

Instance Method Summary collapse

Methods inherited from Ducky::Source

#document, #response

Constructor Details

#initialize(method, version) ⇒ Core

Returns a new instance of Core.



7
8
9
10
11
12
# File 'lib/ducky/sources/core.rb', line 7

def initialize(method, version)
  @method = method
  @version = version

  super(method)
end

Instance Method Details

#lookupObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ducky/sources/core.rb', line 14

def lookup
  elements = document.css(selector)
  information = {
    :head => [],
    :body => [],
    :source => "",
    :footer => "",
    :url => url
  }

  elements.each do |element|
    element.css(".method-heading").each do |call|
      information[:head] << call.inner_text.
        gsub("click to toggle source", "").strip
    end

    information[:body] = element.
      css('div:not(.method-source-code):not(.aliases)').last
    source = element.css('.method-source-code').each do |source|
      information[:source] = source.content
    end

    element.css('.aliases').each do |a|
      information[:footer] << a << "\n"
    end

    information[:footer].strip!
  end

  unless elements.any?
    handle_error
  else
    information
  end

rescue Faraday::ResourceNotFound
  no_method!
end