module DocToDash
  class YardParser
    def initialize(doc_directory)
      @doc_directory = doc_directory

      fix_css_file
    end

    def fix_css_file
      File.open(@doc_directory + '/css/style.css', 'a') { |file| file.write('#header, .showSource, .inheritanceTree, .inheritName, h2 small { display: none; } .source_code, .fullTree { display: block !important; }') }
    end

    def parse_classes
      classes_file = File.read(@doc_directory + '/class_list.html')
      classes_html = Nokogiri::HTML(classes_file)
      classes      = []

      classes_html.xpath('//li').children.select{|c| c.name == "span"}.each do |method|
        a     = method.children.first
        title = a.children.first.to_s.gsub('#', '')
        href  = a["href"].to_s

        classes << [href, title] unless title == "Top Level Namespace"
      end

      classes
    end

    def parse_methods
      methods_file = File.read(@doc_directory + '/method_list.html')
      methods_html = Nokogiri::HTML(methods_file)
      methods      = []

      methods_html.xpath('//li').children.select{|c| c.name == "span"}.each do |method|
        a     = method.children.first
        href  = a["href"].to_s
        name  = a["title"].to_s.gsub(/\((.+)\)/, '').strip! # Strip the (ClassName) and whitespace.

        methods << [href, name]
      end

      methods
    end
  end
end
module DocToDash
  class YardParser
    def initialize(doc_directory)
      @doc_directory = doc_directory

      fix_css_file
    end

    def fix_css_file
      File.open(@doc_directory + '/css/style.css', 'a') { |file| file.write('#header, .showSource, .inheritanceTree, .inheritName, h2 small { display: none; } .source_code, .fullTree { display: block !important; }') }
    end

    def parse_classes
      classes_file = File.read(@doc_directory + '/class_list.html')
      classes_html = Nokogiri::HTML(classes_file)
      classes      = []

      classes_html.css('span.object_link').each do |method|
        a     = method.children.first
        title = a.children.first.to_s.gsub('#', '')
        href  = a["href"].to_s

        classes << [href, title] unless title == "Top Level Namespace"
      end

      classes
    end

    def parse_methods
      methods_file = File.read(@doc_directory + '/method_list.html')
      methods_html = Nokogiri::HTML(methods_file)
      methods      = []

      methods_html.css('span.object_link').each do |method|
        a     = method.children.first
        href  = a["href"].to_s
        name  = a["title"].to_s.gsub(/\((.+)\)/, '').strip! # Strip the (ClassName) and whitespace.

        methods << [href, name]
      end

      methods
    end
  end
end

Fix 0.9.0 breaking YARD change
Fix 0.9.0 breaking YARD change

>= 0.9.0 in YARD version changes the DOM structure of the templates
 which broke the nokogiri finder. This results in the docset being
 empty, changing the nokogiri the finder fixes the problem. This change
 also should be backwards compatible because the tag is still present in
 older versions.

https://github.com/lsegal/yard/commit/be17c0fec5022d20dce9f239b06d3055b588be0d
