Class: CanIUse::UserAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/can_i_use/user_agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_agent_string) ⇒ UserAgent

Returns a new instance of UserAgent.


7
8
9
# File 'lib/can_i_use/user_agent.rb', line 7

def initialize(user_agent_string)
  @user_agent_string = user_agent_string
end

Instance Attribute Details

#user_agent_stringObject

Returns the value of attribute user_agent_string


5
6
7
# File 'lib/can_i_use/user_agent.rb', line 5

def user_agent_string
  @user_agent_string
end

Instance Method Details

#supports?(feature_name, support_type = :yes) ⇒ Boolean

Returns:

  • (Boolean)

11
12
13
14
15
16
# File 'lib/can_i_use/user_agent.rb', line 11

def supports?(feature_name, support_type = :yes)
  feature = Feature.new(feature_name)
  return false unless browser = feature.for_browser(user_agent.family)
  return false unless supported_from_version = browser.supported_from_version(support_type)
  Gem::Version.new(user_agent.version.to_s.dup) >= Gem::Version.new(supported_from_version.to_s.dup)
end