Class: DocToDash::YardParser

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_to_dash/parsers/yard_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc_directory) ⇒ YardParser

Returns a new instance of YardParser.



3
4
5
6
7
# File 'lib/doc_to_dash/parsers/yard_parser.rb', line 3

def initialize(doc_directory)
  @doc_directory = doc_directory

  fix_css_file
end

Instance Method Details

#fix_css_fileObject



9
10
11
# File 'lib/doc_to_dash/parsers/yard_parser.rb', line 9

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

#parse_classesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/doc_to_dash/parsers/yard_parser.rb', line 13

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

#parse_methodsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/doc_to_dash/parsers/yard_parser.rb', line 29

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