class Hiroiyomi::Html::DOMParserHelper

DOMParserHelper

Public Class Methods

cur_pos(file, char) click to toggle source
# File lib/hiroiyomi/html/dom_parser_helper.rb, line 8
def cur_pos(file, char)
  file.ungetc(char) # In order to get current position correctly
  cur_pos = file.pos
  file.getc # drop <
  cur_pos
end
extract_cddata(file) click to toggle source

after <![

# File lib/hiroiyomi/html/dom_parser_helper.rb, line 59
def extract_cddata(file)
  cur_pos = file.pos
  c = file.getc
  return "#{c}#{extract_text_with_symbols(file, ']')}" if c == '[' # CDDATA
  file.pos = cur_pos
  nil
end
extract_comments(file) click to toggle source

after <!-

# File lib/hiroiyomi/html/dom_parser_helper.rb, line 68
def extract_comments(file)
  cur_pos = file.pos
  c = file.getc
  return "#{c}#{extract_text_with_symbols(file, '-')}" if c == '-' # Comment
  file.pos = cur_pos
  nil
end
extract_string(file) click to toggle source

rubocop:disable Metrics/MethodLength string of <.+ or “.+”

# File lib/hiroiyomi/html/dom_parser_helper.rb, line 26
def extract_string(file)
  skip_ignore_chars(file)
  string = ''
  while (c = file.getc)
    case c
    when /[\w-]/
      string += c
    else
      file.ungetc(c)
      break
    end
  end
  string.gsub(/[\t\r\n]/, '').strip
end
extract_text_with_symbols(file, char_before_last_char = ']', last_char = '>') click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/hiroiyomi/html/dom_parser_helper.rb, line 43
def extract_text_with_symbols(file, char_before_last_char = ']', last_char = '>')
  string = ''
  while (c = file.getc)
    string += c
    next_c = file.getc
    if c == char_before_last_char && last_char == next_c
      string += next_c
      break
    end
    file.ungetc(next_c)
  end
  string
end
skip_ignore_chars(file) click to toggle source
# File lib/hiroiyomi/html/dom_parser_helper.rb, line 15
def skip_ignore_chars(file)
  while (c = file.getc)
    unless /[\t\n\r\s]/.match?(c)
      file.ungetc(c)
      return
    end
  end
end