Class: WurflDevice::Capability
- Inherits:
-
Hash
- Object
- Hash
- WurflDevice::Capability
show all
- Defined in:
- lib/wurfl_device/capability.rb
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}) ⇒ Capability
Returns a new instance of Capability.
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/wurfl_device/capability.rb', line 3
def initialize(hash={})
super()
hash.each do |key, value|
if value.kind_of?(Hash)
self[convert_key(key)] = Capability.new(value)
else
self[convert_key(key)] = value
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Magic predicates. For instance:
capability.force? capability.shebang capability.test_framework?(:rspec)
need to rewrite this for deep hash entries use capability to group mapping
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/wurfl_device/capability.rb', line 63
def method_missing(method, *args, &block)
method = method.to_s
if method =~ /^(\w+)\?$/
if args.empty?
!!get_value($1)
else
get_value($1) == args.first
end
else
get_value(method)
end
end
|
Instance Method Details
#[](key) ⇒ Object
14
15
16
|
# File 'lib/wurfl_device/capability.rb', line 14
def [](key)
super(convert_key(key))
end
|
#[]=(key, value) ⇒ Object
18
19
20
|
# File 'lib/wurfl_device/capability.rb', line 18
def []=(key, value)
super(convert_key(key), value)
end
|
#delete(key) ⇒ Object
22
23
24
|
# File 'lib/wurfl_device/capability.rb', line 22
def delete(key)
super(convert_key(key))
end
|
#merge(other) ⇒ Object
30
31
32
|
# File 'lib/wurfl_device/capability.rb', line 30
def merge(other)
dup.merge!(other)
end
|
#merge!(other) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/wurfl_device/capability.rb', line 34
def merge!(other)
other.each do |key, value|
self[convert_key(key)] = value
end
self
end
|
#values_at(*indices) ⇒ Object
26
27
28
|
# File 'lib/wurfl_device/capability.rb', line 26
def values_at(*indices)
indices.collect { |key| self[convert_key(key)] }
end
|