Class: Docs::Node::EntriesFilter

Inherits:
EntriesFilter show all
Defined in:
lib/docs/filters/node/entries.rb

Constant Summary collapse

REPLACE_NAMES =
{
'debugger' => 'Debugger',
'addons'   => 'C/C++ Addons',
'modules'  => 'module' }
REPLACE_TYPES =
{
'Addons'                 => 'Miscellaneous',
'Debugger'               => 'Miscellaneous',
'os'                     => 'OS',
'StringDecoder'          => 'String Decoder',
'TLS (SSL)'              => 'TLS/SSL',
'UDP / Datagram Sockets' => 'UDP/Datagram',
'Executing JavaScript'   => 'VM' }
IGNORE_DEFAULT_ENTRY =
%w(globals timers domain buffer)

Constants inherited from Filter

Filter::SCHEME_RGX

Instance Method Summary collapse

Methods inherited from EntriesFilter

#build_entries, #build_entry, #call, #default_entry, #entries, #name, #path, #type

Methods inherited from Filter

#absolute_url_string?, #at_css, #at_xpath, #base_url, #css, #current_url, #fragment_url_string?, #initial_page?, #parse_html, #relative_url_string?, #root_page?, #root_path, #root_url, #slug, #subpath, #subpath_to, #xpath

Instance Method Details

#additional_entriesObject


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/docs/filters/node/entries.rb', line 33

def additional_entries
  return [] if type == 'Miscellaneous'

  klass = nil
  entries = []

  css('> [id]').each do |node|
    next if node.name == 'h1'

    klass = nil if node.name == 'h2'
    name = node.content.strip

    # Skip constructors
    if name.start_with? 'new '
      next
    end

    # Ignore most global objects (found elsewhere)
    if type == 'Global Objects'
      entries << [name, node['id']] if name.start_with?('_') || name == 'global'
      next
    end

    # Classes
    if name.gsub! 'Class: ', ''
      name.remove! 'events.' # EventEmitter
      klass = name
      entries << [name, node['id']]
      next
    end

    # Events
    if name.sub! %r{\AEvent: '(.+)'\z}, '\1'
      name << " event (#{klass || type})"
      entries << [name, node['id']]
      next
    end

    name.gsub! %r{\(.*?\);?}, '()'
    name.gsub! %r{\[.+?\]}, '[]'
    name.remove! 'assert(), ' # assert/assert.ok

    # Skip all that start with an uppercase letter ("Example") or include a space ("exports alias")
    next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method')

    # Differentiate server classes (http, https, net, etc.)
    name.sub!('server.') { "#{(klass || 'https').sub('.', '_').downcase!}." }
    # Differentiate socket classes (net, dgram, etc.)
    name.sub!('socket.') { "#{klass.sub('.', '_').downcase!}." }

    name.remove! 'Class Method:'
    name.sub! 'buf.',     'buffer.'
    name.sub! 'buf[',     'buffer['
    name.sub! 'child.',   'childprocess.'
    name.sub! 'decoder.', 'stringdecoder.'
    name.sub! 'emitter.', 'eventemitter.'
    name.sub! %r{\Arl\.}, 'interface.'
    name.sub! 'rs.',      'readstream.'
    name.sub! 'ws.',      'writestream.'

    # Skip duplicates (listen, connect, etc.)
    unless name == entries[-1].try(:first) || name == entries[-2].try(:first)
      entries << [name, node['id']]
    end
  end

  entries
end

#get_nameObject


24
25
26
# File 'lib/docs/filters/node/entries.rb', line 24

def get_name
  REPLACE_NAMES[slug] || slug
end

#get_typeObject


28
29
30
31
# File 'lib/docs/filters/node/entries.rb', line 28

def get_type
  type = at_css('h1').content.strip
  REPLACE_TYPES[type] || "#{type.first.upcase}#{type[1..-1]}"
end

#include_default_entry?Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/docs/filters/node/entries.rb', line 20

def include_default_entry?
  !IGNORE_DEFAULT_ENTRY.include?(slug)
end