class DeviceDetector::Parser

Private Instance Methods

build_regex(src, prefix = true) click to toggle source
# File lib/device_detector_regexes.rb, line 44
def build_regex(src, prefix = true)
  Regexp.new (prefix ? '(?:^|[^A-Z0-9\-_]|[^A-Z0-9\-]_|sprd-)(?:' + src + ')' : src), Regexp::IGNORECASE
end
filepaths() click to toggle source
# File lib/device_detector_regexes.rb, line 24
def filepaths
  filenames.each_with_object([]) do |filename, filenames|
    # push custom files first due to higher precedence lookup than default files
    custom_file_path = File.expand_path(filename, File.join(DeviceDetector.config.dir, 'regexes'))
    filenames << [filename.to_sym, custom_file_path] if File.exist?(custom_file_path)

    filenames << [filename.to_sym, File.join(ROOT, 'regexes', filename)]
  end
end
parse_regexes(path, raw_regexes) click to toggle source
# File lib/device_detector_regexes.rb, line 34
def parse_regexes(path, raw_regexes)
  raw_regexes.map do |meta|
    raise "invalid device spec: #{meta.inspect}" unless meta[:regex].is_a? String

    meta[:regex] = build_regex(meta[:regex], meta[:prefix])
    meta[:path] = path
    meta
  end
end