Module: Represent::SystemHelper

Defined in:
lib/represent/system_helper.rb

Instance Method Summary collapse

Instance Method Details

#browser_is?(name) ⇒ Boolean

check the current browser (via user agent) for the following: :mozilla / :firefox :ie6 :ie7 :ie :iphone :safari

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/represent/system_helper.rb', line 10

def browser_is? name
  name = name.to_s.strip

  return true if browser_name == name
  return true if (name == 'mozilla' or name == "firefox") && browser_name == 'gecko'
  return true if name == 'ie6' && browser_name.index('ie6')
  return true if name == 'ie7' && browser_name.index('ie7')
  return true if name == 'ie' && browser_name.index('ie')
  return true if name == 'iphone' && browser_name == 'iphone'
  return true if name == 'webkit' && browser_name == 'safari'
end

#browser_nameObject

find the current browser name



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/represent/system_helper.rb', line 23

def browser_name
  @browser_name ||= begin
    ua = request.user_agent.to_s.downcase
    if ua.index('msie') && !ua.index('opera') && !ua.index('webtv')
      'ie'+ua[ua.index('msie')+5].chr
    elsif ua.index('gecko/') 
      'gecko'
    elsif ua.index('opera')
      'opera'
    elsif ua.index('konqueror') 
      'konqueror'
    elsif ua.index('iphone')
      'iphone'
    elsif ua.index('applewebkit/')
      'safari'
    elsif ua.index('mozilla/')
      'gecko'
    else
      ""
    end
  end
end

#linux?Boolean

Works on Debian and Ubuntu, don’t have anything else to test on.

Returns:

  • (Boolean)


52
53
54
# File 'lib/represent/system_helper.rb', line 52

def linux?
  (/linux/).match(RUBY_PLATFORM) ? true : false
end

#mac?Boolean

Works on my MacBook Pro, don’t have anything else to test on,

Returns:

  • (Boolean)


57
58
59
# File 'lib/represent/system_helper.rb', line 57

def mac?
  (/darwin/).match(RUBY_PLATFORM) ? true : false
end

#windows?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/represent/system_helper.rb', line 46

def windows?
  # Can't match for just 'win' cause it will match darwin as well.
  (/win32|mswin|mingw/).match(RUBY_PLATFORM) ? true : false
end