Class: Docs::Postgresql::EntriesFilter

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

Constant Summary collapse

REPLACE_NAMES =
{
'Sorting Rows'                    => 'ORDER BY',
'Select Lists'                    => 'SELECT Lists',
'Data Type Formatting Functions'  => 'Formatting Functions',
'Enum Support Functions'          => 'Enum Functions',
'Row and Array Comparisons'       => 'Array Comparisons',
'Sequence Manipulation Functions' => 'Sequence Functions',
'System Administration Functions' => 'Administration Functions',
'System Information Functions'    => 'Information Functions' }
PREPEND_TYPES =
[
'Type Conversion',
'Full Text Search',
'Performance Tips',
'Server Configuration',
'Monitoring' ]
REPLACE_TYPES =
{
'Routine Database Maintenance Tasks' => 'Maintenance',
'High Availability, Load Balancing, and Replication' => 'High Availability',
'Monitoring Database Activity' => 'Monitoring',
'Monitoring Disk Usage' => 'Monitoring',
'Reliability and the Write-Ahead Log' => 'Write-Ahead Log' }
SKIP_ENTRIES_SLUGS =
[
'config-setting',
'applevel-consistency' ]
SKIP_ENTRIES_TYPES =
[
'Localization',
'Type Conversion',
'Full Text Search',
'Performance Tips',
'Client Authentication',
'Managing Databases',
'Maintenance',
'Backup and Restore',
'High Availability',
'Monitoring' ]

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


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
# File 'lib/docs/filters/postgresql/entries.rb', line 59

def additional_entries
  return [] if skip_additional_entries?
  return config_additional_entries if type && type.include?('Configuration')
  return data_types_additional_entries if type == 'Data Types'
  return get_heading_entries('h3[id]') if slug == 'functions-xml'

  entries = get_heading_entries('h2[id]')

  case slug
  when 'queries-union'
    entries.concat get_custom_entries('p > .LITERAL:first-child')
  when 'queries-table-expressions'
    entries.concat get_heading_entries('h3[id]')
    entries.concat get_custom_entries('dt > .LITERAL:first-child')
  when 'functions-logical'
    entries.concat get_custom_entries('> table td:first-child > code')
  when 'functions-formatting'
    entries.concat get_custom_entries('#FUNCTIONS-FORMATTING-TABLE td:first-child > code')
  when 'functions-admin'
    entries.concat get_custom_entries('.TABLE td:first-child > code')
  when 'functions-string'
    entries.concat get_custom_entries('> div[id^="FUNC"] td:first-child > code')
  else
    if type && type.start_with?('Functions')
      entries.concat get_custom_entries('> .TABLE td:first-child > code:first-child')
      entries.concat %w(IS NULL BETWEEN DISTINCT\ FROM).map { |name| ["#{self.name}: #{name}"] } if slug == 'functions-comparison'
    end
  end

  entries
end

#additional_entry_prefixObject


169
170
171
# File 'lib/docs/filters/postgresql/entries.rb', line 169

def additional_entry_prefix
  type.dup.gsub!('Functions: ', '') || self.name
end

#base_nameObject


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

def base_name
  @base_name ||= clean_heading_name(at_css('h1').content)
end

#clean_heading_name(name) ⇒ Object


134
135
136
137
138
139
140
# File 'lib/docs/filters/postgresql/entries.rb', line 134

def clean_heading_name(name)
  name.remove! %r{\A[\d\.\s]+}
  name.remove! 'Using '
  name.remove! %r{\AThe }
  name.remove! ' (Common Table Expressions)'
  name
end

#config_additional_entriesObject


91
92
93
94
95
96
# File 'lib/docs/filters/postgresql/entries.rb', line 91

def config_additional_entries
  css('.VARIABLELIST dt[id]').map do |node|
    name = node.at_css('.VARNAME').content
    ["Config: #{name}", node['id']]
  end
end

#data_types_additional_entriesObject


98
99
100
101
102
103
104
105
106
107
108
# File 'lib/docs/filters/postgresql/entries.rb', line 98

def data_types_additional_entries
  selector = case slug
  when 'rangetypes'
    'li > p > .TYPE:first-child'
  when 'datatype-textsearch'
    '.SECT2 > .TYPE'
  else
    '.CALSTABLE td:first-child > .TYPE'
  end
  get_custom_entries(selector)
end

#get_custom_entries(selector) ⇒ Object


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/docs/filters/postgresql/entries.rb', line 150

def get_custom_entries(selector)
  css(selector).each_with_object([]) do |node, entries|
    name = node.content
    name.remove! %r{\(.*?\)}m
    name.remove! %r{\[.*?\]}m
    name.squeeze! ' '
    name.remove! %r{\([^\)]*\z} # bug fix: json_populate_record
    name = '||' if name.include? ' || '
    id = name.gsub(/[^a-z0-9\-_]/) { |char| char.ord }
    id = id.parameterize
    name.prepend "#{additional_entry_prefix}: "

    unless entries.any? { |entry| entry[0] == name }
      node['id'] = id
      entries << [name, id]
    end
  end
end

#get_heading_entries(selector) ⇒ Object


142
143
144
145
146
147
148
# File 'lib/docs/filters/postgresql/entries.rb', line 142

def get_heading_entries(selector)
  css(selector).each_with_object([]) do |node, entries|
    name = node.content
    clean_heading_name(name)
    entries << ["#{additional_entry_prefix}: #{name}", node['id']] unless skip_heading?(name)
  end
end

#get_nameObject


32
33
34
35
36
37
38
39
40
# File 'lib/docs/filters/postgresql/entries.rb', line 32

def get_name
  if %w(Overview Introduction).include?(base_name)
    result[:pg_chapter_name]
  elsif PREPEND_TYPES.include?(type)
    "#{type}: #{base_name}"
  else
    REPLACE_NAMES[base_name] || base_name
  end
end

#get_typeObject


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/docs/filters/postgresql/entries.rb', line 42

def get_type
  return if initial_page?

  if result[:pg_up_path] == 'sql-commands.html'
    'Commands'
  elsif result[:pg_up_path].start_with?('reference-')
    'Applications'
  elsif type = result[:pg_chapter_name]
    if type.start_with?('Func') && (match = base_name.match(/\A(?!Form|Seq|Set|Enum)(.+) Func/))
      "Functions: #{match[1]}"
    else
      type.remove! 'SQL '
      REPLACE_TYPES[type] || type
    end
  end
end

#include_default_entry?Boolean

Returns:

  • (Boolean)

110
111
112
# File 'lib/docs/filters/postgresql/entries.rb', line 110

def include_default_entry?
  !initial_page? && !at_css('.TOC')
end

#skip_additional_entries?Boolean

Returns:

  • (Boolean)

130
131
132
# File 'lib/docs/filters/postgresql/entries.rb', line 130

def skip_additional_entries?
  SKIP_ENTRIES_SLUGS.include?(slug) || SKIP_ENTRIES_TYPES.include?(type)
end

#skip_heading?(name) ⇒ Boolean

Returns:

  • (Boolean)

173
174
175
176
# File 'lib/docs/filters/postgresql/entries.rb', line 173

def skip_heading?(name)
  %w(Usage\ Patterns Portability Caveats Overview).include?(name) ||
  (type.start_with?('Functions') && slug != 'functions-xml' && name.split.first.upcase!)
end