Sha256: 140194e8384962862ff1c796c699cd3f3e8552be853f5e4a5bf83a2fba0edd4f

Contents?: true

Size: 924 Bytes

Versions: 6

Compression:

Stored size: 924 Bytes

Contents

# encoding: utf-8

module UseragentParser
  class DeviceParser
    attr_accessor :pattern, :user_agent_re, :device_replacement

    def initialize(pattern, device_replacement = nil)
      @pattern = pattern
      @user_agent_re = Regexp.compile(pattern)
      @device_replacement = device_replacement
    end

    def match_spans(user_agent_string)
      match_spans = []
      match = @user_agent_re.match(user_agent_string)
      if match
        # Return the offsets
      end
    end

    def parse(user_agent_string)
      device = nil
      match = @user_agent_re.match(user_agent_string)
      if match
        if @device_replacement
          if %r'\$1'.match @device_replacement
            device = @device_replacement.gsub(%r'\$1', match[1])
          else
            device = @device_replacement
          end
        else
          device = match[1]
        end
      end
      return device
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
useragent_parser-0.2.3 lib/useragent_parser/parsers/device_parser.rb
useragent_parser-0.2.2 lib/useragent_parser/parsers/device_parser.rb
useragent_parser-0.2.1 lib/useragent_parser/parsers/device_parser.rb
useragent_parser-0.2.0 lib/useragent_parser/parsers/device_parser.rb
useragent_parser-0.1.1 lib/useragent_parser/parsers/device_parser.rb
useragent_parser-0.1.0 lib/useragent_parser/parsers/device_parser.rb