Class: Ducky::Sources::Gem

Inherits:
Ducky::Source show all
Defined in:
lib/ducky/sources/gem.rb

Instance Method Summary collapse

Methods inherited from Ducky::Source

#document, #response

Constructor Details

#initialize(name, method, version = :guess) ⇒ Gem

Returns a new instance of Gem.



5
6
7
8
9
10
11
# File 'lib/ducky/sources/gem.rb', line 5

def initialize(name, method, version = :guess)
  @name = name
  @method = method
  @version = version

  super(method)
end

Instance Method Details

#lookupObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ducky/sources/gem.rb', line 13

def lookup
  methods = document.css('#method_details .method_details')
  no_method! unless methods.any?

  methods.each do |method|
    method.css('.signature').each do |sig|
      information[:head] << sig.inner_text.strip
    end

    information[:body] = document.
      css('.docstring .discussion').last

    information[:footer] =
      create_footer(document.css('.tags').last)

    information[:source] = document.
      css('.source_code pre.code').last.inner_text
  end

  information

rescue Faraday::ResourceNotFound
  no_method!
end