Class: Docs::Moment::EntriesFilter

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

Constant Summary collapse

IGNORE_IDS =
%w(
i18n-loading-into-nodejs
i18n-loading-into-browser
i18n-adding-locale
i18n-getting-locale)

Constants inherited from Filter

Filter::SCHEME_RGX

Instance Method Summary collapse

Methods inherited from EntriesFilter

#build_entries, #build_entry, #call, #default_entry, #entries, #get_name, #get_type, #include_default_entry?, #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


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/docs/filters/moment/entries.rb', line 10

def additional_entries
  entries = []
  type = nil

  css('[id]').each do |node|
    if node.name == 'h2'
      type = node.content
      next
    end

    next unless node.name == 'h3'
    next if IGNORE_IDS.include?(node['id'])

    if node['id'] == 'utilities-invalid' # bug fix
      name = 'moment.invalid()'
    elsif %w(Display Durations Get\ +\ Set i18n Manipulate Query Utilities).include?(type) ||
          %w(parsing-is-valid parsing-parse-zone parsing-unix-timestamp parsing-utc customization-relative-time-threshold).include?(node['id'])
      name = node.next_element.content[/moment(?:\(.*?\))?\.(?:duration\(\)\.)?\w+/]
      name.sub! %r{\(.*?\)\.}, '#'
      name << '()'
    elsif type == 'Customize'
      name = node.next_element.content[/moment.locale\(.+?\{\s+(\w+)/, 1]
      name.prepend 'Locale#'
    else
      name = node.content.strip
      name.remove! %r{\s[\d\.]+[\s\+]*\z} # remove version number
      name.remove! %r{\s\(.+\)\z}  # remove parenthesis
      name.prepend 'Parse: ' if type == 'Parse'
    end

    entries << [name, node['id'], type]
  end

  entries
end