Class: WurflCloud::DeviceCapabilities
- Inherits:
-
Object
- Object
- WurflCloud::DeviceCapabilities
- Defined in:
- lib/wurfl_cloud/device_capabilities.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #empty? ⇒ Boolean
- #has_key?(key) ⇒ Boolean
-
#initialize(ua = nil) ⇒ DeviceCapabilities
constructor
A new instance of DeviceCapabilities.
- #merge(newvalues) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(ua = nil) ⇒ DeviceCapabilities
Returns a new instance of DeviceCapabilities.
12 13 14 15 16 17 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 12 def initialize(ua = nil) @capabilities = {} @mtime = Time.at(0) @id = nil @user_agent = ua end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 10 def id @id end |
#mtime ⇒ Object
Returns the value of attribute mtime.
10 11 12 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 10 def mtime @mtime end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
10 11 12 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 10 def user_agent @user_agent end |
Class Method Details
.parse(json) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 43 def parse(json) object = JSON.parse(json) new.tap do |device_capabilities| object["capabilities"].each do |key,value| device_capabilities[key] = cast_value(value) end device_capabilities.id = object["id"] device_capabilities["id"] = object["id"] device_capabilities.mtime = Time.at(object["mtime"].to_i) end rescue raise WurflCloud::Errors::MalformedResponseError.new end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 19 def [](key) @capabilities[key] end |
#[]=(key, value) ⇒ Object
23 24 25 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 23 def []=(key, value) @capabilities[key] = value end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 31 def empty? @capabilities.empty? end |
#has_key?(key) ⇒ Boolean
35 36 37 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 35 def has_key?(key) @capabilities.has_key?(key) end |
#merge(newvalues) ⇒ Object
27 28 29 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 27 def merge(newvalues) @capabilities.merge!(newvalues) end |
#to_hash ⇒ Object
39 40 41 |
# File 'lib/wurfl_cloud/device_capabilities.rb', line 39 def to_hash @capabilities.clone end |