Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
Removed repetition in class method names.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Jun 21, 2011
1 parent d42e4da commit 306cb7d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/user_agent.rb
@@ -1,12 +1,12 @@
class UserAgent class UserAgent
def self.engine_version_for_user_agent(string) def self.engine_version(string)
if string =~ /#{engine_for_user_agent(string)}[\/ ]([\d\w\.\-]+)/i if string =~ /#{engine(string)}[\/ ]([\d\w\.\-]+)/i
$1 $1
end end
end end


def self.version_for_user_agent(string) def self.version(string)
case name = name_for_user_agent(string) case name = browser_name(string)
when :chrome ; $1 if string =~ /chrome\/([\d\w\.\-]+)/i when :chrome ; $1 if string =~ /chrome\/([\d\w\.\-]+)/i
when :safari ; $1 if string =~ /version\/([\d\w\.\-]+)/i when :safari ; $1 if string =~ /version\/([\d\w\.\-]+)/i
when :ps3 ; $1 if string =~ /([\d\w\.\-]+)\)\s*$/i when :ps3 ; $1 if string =~ /([\d\w\.\-]+)\)\s*$/i
Expand All @@ -15,7 +15,7 @@ def self.version_for_user_agent(string)
end end
end end


def self.engine_for_user_agent(string) def self.engine(string)
case string case string
when /webkit/i ; :webkit when /webkit/i ; :webkit
when /khtml/i ; :khtml when /khtml/i ; :khtml
Expand All @@ -28,7 +28,7 @@ def self.engine_for_user_agent(string)
end end
end end


def self.os_for_user_agent(string) def self.os(string)
case string case string
when /windows nt 6\.0/i ; 'Windows Vista' when /windows nt 6\.0/i ; 'Windows Vista'
when /windows nt 6\.\d+/i ; 'Windows 7' when /windows nt 6\.\d+/i ; 'Windows 7'
Expand All @@ -46,7 +46,7 @@ def self.os_for_user_agent(string)
end end
end end


def self.name_for_user_agent(string) def self.browser_name(string)
case string case string
when /konqueror/i ; :konqueror when /konqueror/i ; :konqueror
when /chrome/i ; :chrome when /chrome/i ; :chrome
Expand All @@ -60,7 +60,7 @@ def self.name_for_user_agent(string)
end end
end end


def self.platform_for_user_agent(string) def self.platform(string)
case string case string
when /windows/i ; :windows when /windows/i ; :windows
when /macintosh/i ; :macintosh when /macintosh/i ; :macintosh
Expand All @@ -80,27 +80,27 @@ def initialize(source)
end end


def name def name
self.class.name_for_user_agent(source) self.class.browser_name(source)
end end


def version def version
self.class.version_for_user_agent(source) self.class.version(source)
end end


def engine def engine
self.class.engine_for_user_agent(source) self.class.engine(source)
end end


def engine_version def engine_version
self.class.engine_version_for_user_agent(source) self.class.engine_version(source)
end end


def os def os
self.class.os_for_user_agent(source) self.class.os(source)
end end


def platform def platform
self.class.platform_for_user_agent(source) self.class.platform(source)
end end


def to_s def to_s
Expand Down

0 comments on commit 306cb7d

Please sign in to comment.