Class: Sniffux

Inherits:
Object
  • Object
show all
Defined in:
lib/sniffux.rb,
lib/sniffux/version.rb,
lib/sniffux/action_controller.rb

Defined Under Namespace

Modules: ActionController

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Sniffux

Returns a new instance of Sniffux.



8
9
10
# File 'lib/sniffux.rb', line 8

def initialize(string)
  @user_agent = UserAgent.parse(string)
end

Instance Method Details

#cancel_left?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/sniffux.rb', line 12

def cancel_left?
  # OS X, iOS, Linux, ChromeOS, WebOS, Haiku
  # Default because it's better:
  # http://uxmovement.com/buttons/why-ok-buttons-in-dialog-boxes-work-best-on-the-right/
  !cancel_right?
end

#cancel_right?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/sniffux.rb', line 19

def cancel_right?
  # Windows, Android, Amiga (AROS)
  %w(Windows).include?(@user_agent.platform) ||
  %w(AROS).include?(@user_agent.os) ||
  !!(@user_agent.os =~ /Android/)
end

#cancel_sideObject



26
27
28
29
30
31
32
# File 'lib/sniffux.rb', line 26

def cancel_side
  if cancel_right?
    'right'
  else
    'left'
  end
end

#close_left?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/sniffux.rb', line 50

def close_left?
  # OS X, iOS, Linux (Ubuntu, can vary), Haiku, Amiga
  # Default because it matches having Cancel on the left
  !close_right?
end

#close_right?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/sniffux.rb', line 56

def close_right?
  # Windows, ChromeOS
  %w(Windows).include?(@user_agent.platform) ||
  !!(@user_agent.os =~ /CrOS/)
end

#close_sideObject



62
63
64
65
66
67
68
# File 'lib/sniffux.rb', line 62

def close_side
  if close_right?
    'right'
  else
    'left'
  end
end

#ok_left?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/sniffux.rb', line 34

def ok_left?
  cancel_right?
end

#ok_right?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/sniffux.rb', line 38

def ok_right?
  cancel_left?
end

#ok_sideObject



42
43
44
45
46
47
48
# File 'lib/sniffux.rb', line 42

def ok_side
  if ok_right?
    'right'
  else
    'left'
  end
end