Class: CVEasy::Query

Inherits:
Keyword show all
Defined in:
lib/CVEasy/query.rb

Instance Method Summary collapse

Methods inherited from Keyword

#description, #more, #name, #url

Constructor Details

#initialize(options = {}, &block) ⇒ Query

Returns a new instance of Query.



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
# File 'lib/CVEasy/query.rb', line 15

def initialize(options={}, &block)

  @year = options[:year]
  @cve = options[:cve]
  @keyword = options[:keyword]

  if options[:keyword]

    @url = "#{KEYWORD_URL}#{URI.escape(@keyword)}"
    @html ||= Nokogiri::HTML(open(@url))

    @html.css('#TableWithRules tr').each do |td|
      # Skip The First TD - Used as TH.
      next if td.at('a').nil?

      block.call(Keyword.new(td, @html)) if block

    end
  else

    @url = "#{CVE_URL}#{@year}-#{URI.escape(@cve)}"
    @html = Nokogiri::HTML(open(@url))
    block.call(Cve.new(@html.at_css('#GeneratedTable'))) if block

  end
end

Instance Method Details

#versionObject



42
43
44
# File 'lib/CVEasy/query.rb', line 42

def version
  @version ||= @html.at('.smaller , b:nth-child(2)').inner_text
end