Class: Docs::Python::EntriesFilter

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

Constant Summary collapse

REPLACE_TYPES =
{
'Cryptographic'                           => 'Cryptography',
'Custom Interpreters'                     => 'Interpreters',
'Data Compression & Archiving'            => 'Data Compression',
'Generic Operating System'                => 'Operating System',
'Graphical User Interfaces with Tk'       => 'Tk',
'Internet Data Handling'                  => 'Internet Data',
'Internet Protocols & Support'            => 'Internet',
'Interprocess Communication & Networking' => 'Networking',
'Program Frameworks'                      => 'Frameworks',
'Structured Markup Processing Tools'      => 'Structured Markup' }

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


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/docs/filters/python/entries.rb', line 51

def additional_entries
  return [] if root_page? || !include_default_entry? || name == 'errno'
  clean_id_attributes
  entries = []

  css('.class > dt[id]', '.exception > dt[id]', '.attribute > dt[id]').each do |node|
    entries << [node['id'], node['id']]
  end

  css('.data > dt[id]').each do |node|
    if node['id'].split('.').last.upcase! # skip constants
      entries << [node['id'], node['id']]
    end
  end

  css('.function > dt[id]', '.method > dt[id]', '.classmethod > dt[id]').each do |node|
    entries << [node['id'] + '()', node['id']]
  end

  entries
end

#clean_id_attributesObject


73
74
75
76
77
78
79
80
# File 'lib/docs/filters/python/entries.rb', line 73

def clean_id_attributes
  css('.section > .target[id]').each do |node|
    if dt = node.at_css('+ dl > dt')
      dt['id'] ||= node['id'].remove(/\w+\-/)
    end
    node.remove
  end
end

#get_nameObject


16
17
18
19
20
21
22
23
24
# File 'lib/docs/filters/python/entries.rb', line 16

def get_name
  name = at_css('h1').content
  name.remove! %r{\A[\d\.]+ } # remove list number
  name.remove! "\u{00B6}" # remove pilcrow sign
  name.remove! %r{ [\u{2013}\u{2014}].+\z} # remove text after em/en dash
  name.remove! 'Built-in'
  name.strip!
  name
end

#get_typeObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/docs/filters/python/entries.rb', line 26

def get_type
  return 'Logging' if slug.start_with? 'library/logging'

  type = at_css('.related a[accesskey="U"]').content

  if type == 'The Python Standard Library'
    type = at_css('h1').content
  elsif type.include?('I/O') || %w(select selectors).include?(name)
    type = 'Input/ouput'
  elsif type.start_with? '19'
    type = 'Internet Data Handling'
  end

  type.remove! %r{\A\d+\.\s+} # remove list number
  type.remove! "\u{00b6}" # remove paragraph character
  type.sub! ' and ', ' & '
  [' Services', ' Modules', ' Specific', 'Python '].each { |str| type.remove!(str) }

  REPLACE_TYPES[type] || type
end

#include_default_entry?Boolean


47
48
49
# File 'lib/docs/filters/python/entries.rb', line 47

def include_default_entry?
  !at_css('.body > .section:only-child > .toctree-wrapper:last-child') && !type.in?(%w(Language Superseded))
end