Class: Docs::Javascript::EntriesFilter

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

Constant Summary collapse

TYPES =
%w(Array ArrayBuffer Boolean DataView Date Function Intl JSON Map
Math Number Object Promise RegExp Set String Symbol TypedArray WeakMap
WeakSet)
INTL_OBJECTS =
%w(Collator DateTimeFormat NumberFormat)

Constants inherited from Filter

Filter::SCHEME_RGX

Instance Method Summary collapse

Methods inherited from EntriesFilter

#additional_entries, #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

#get_nameObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/docs/filters/javascript/entries.rb', line 9

def get_name
  if slug.start_with? 'Global_Objects/'
    name, method = *slug.sub('Global_Objects/', '').split('/')
    name.prepend 'Intl.' if INTL_OBJECTS.include?(name)

    if method
      unless method == method.upcase || method == 'NaN'
        method = method[0].downcase + method[1..-1] # e.g. Trim => trim
      end
      name << ".#{method}"
    end

    name
  else
    name = super
    name.remove! 'Functions.'
    name.remove! 'Functions and function scope.'
    name.remove! 'Operators.'
    name.remove! 'Statements.'
    name
  end
end

#get_typeObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/docs/filters/javascript/entries.rb', line 32

def get_type
  if slug.start_with? 'Statements'
    'Statements'
  elsif slug.start_with? 'Operators'
    'Operators'
  elsif slug.start_with?('Functions_and_function_scope') || slug.start_with?('Functions') || slug.include?('GeneratorFunction')
    'Function'
  elsif slug.start_with? 'Global_Objects'
    object, method = *slug.remove('Global_Objects/').split('/')
    if object.end_with? 'Error'
      'Errors'
    elsif INTL_OBJECTS.include?(object)
      'Intl'
    elsif method || TYPES.include?(object)
      object
    else
      'Global Objects'
    end
  else
    'Miscellaneous'
  end
end

#include_default_entry?Boolean


55
56
57
58
59
60
61
62
63
64
# File 'lib/docs/filters/javascript/entries.rb', line 55

def include_default_entry?
  node = doc.at_css '.overheadIndicator'

  # Can't use :first-child because #doc is a DocumentFragment
  return true unless node && node.parent == doc && !node.previous_element

  !node.content.include?('not on a standards track') &&
  !node.content.include?('removed from the Web') &&
  !node.content.include?('could be removed at any time')
end