Class: Cocoadex::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoadex/parser.rb

Overview

DocSet index and html documentation file parser

Constant Summary collapse

GenericReference =
->(title) { title.include?("Reference") }
DeprecatedMethods =
->(title) { title =~ /^Deprecated ([A-Za-z]+) Methods$/ }
ClassReference =
->(title) {
title.include?("Class Reference") or title.include?("Protocol Reference") }
IGNORED_DIRS =
[
  'codinghowtos', 'qa',
  'featuredarticles','navigation',
  'recipes','releasenotes',
  'samplecode','Conceptual',
  'technotes','History',
  'Introduction','GettingStarted'
]
IGNORED_FILES =
[
  'RevisionHistory','Introduction'
]

Class Method Summary collapse

Class Method Details

.ignored?(path) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/cocoadex/parser.rb', line 24

def self.ignored? path
  (path.split('/') & IGNORED_DIRS).size > 0 or
  IGNORED_FILES.include?(File.basename(path).sub('.html','')) or
  (File.basename(path) == 'index.html' && File.exist?(File.join(File.dirname(path),'Reference')))
end

.index_html(docset, path, index) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cocoadex/parser.rb', line 50

def self.index_html docset, path, index
  logger.debug "  Parsing path: #{path}"

  doc = Nokogiri::HTML(IO.read(path))
  if title = doc.css("#IndexTitle").first['content']
    case title
    when ClassReference
      Tokenizer.tokenize_class(docset.name, path, index)
    when GenericReference
      Tokenizer.tokenize_ref(docset.name, path, index)
    when DeprecatedMethods
      # TODO
    else
      # TODO
    end
  end
end

.parse(docset_path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cocoadex/parser.rb', line 30

def self.parse docset_path
  plist = File.join(docset_path,"Contents", "Info.plist")
  if File.exist? plist
    docset = DocSet.new(plist)
    logger.info "Parsing docset tokens in #{docset.name}. This may take a moment..."

    files = Dir.glob(docset_path+"/**/*.html").select {|f| not ignored?(f) }

    pbar  = ProgressBar.new("#{docset.platform} #{docset.version}",files.size)
    files.each_with_index do |f,i|
      index_html(docset,f,i)
      pbar.inc
    end
    pbar.finish

    logger.info "  Tokens Indexed: #{Tokenizer.tokens.size}"
    docset
  end
end