Class: LabClient::LabStruct
- Inherits:
-
Object
- Object
- LabClient::LabStruct
show all
- Includes:
- CurlHelper
- Defined in:
- lib/labclient/lab_struct.rb
Overview
Unique inherited class to not override top level LabStruct
Direct Known Subclasses
Klass
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from CurlHelper
#curl
Constructor Details
#initialize(hash = {}) ⇒ LabStruct
Returns a new instance of LabStruct.
9
10
11
12
13
14
15
|
# File 'lib/labclient/lab_struct.rb', line 9
def initialize(hash = {})
@table = if hash.instance_of?(LabClient::LabStruct)
hash.to_h
else
hash
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *_args) ⇒ Object
46
47
48
|
# File 'lib/labclient/lab_struct.rb', line 46
def method_missing(method, *_args)
@table[method] if @table.keys.include?(method)
end
|
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
7
8
9
|
# File 'lib/labclient/lab_struct.rb', line 7
def response
@response
end
|
#table ⇒ Object
Returns the value of attribute table.
7
8
9
|
# File 'lib/labclient/lab_struct.rb', line 7
def table
@table
end
|
Instance Method Details
#[](name) ⇒ Object
62
63
64
|
# File 'lib/labclient/lab_struct.rb', line 62
def [](name)
@table[name.to_sym]
end
|
#[]=(name, value) ⇒ Object
58
59
60
|
# File 'lib/labclient/lab_struct.rb', line 58
def []=(name, value)
@table[name] = value
end
|
#as_json(*args) ⇒ Object
29
30
31
|
# File 'lib/labclient/lab_struct.rb', line 29
def as_json(*args)
super.as_json['table']
end
|
#client ⇒ Object
37
38
39
|
# File 'lib/labclient/lab_struct.rb', line 37
def client
response.client
end
|
#inspect ⇒ Object
25
26
27
|
# File 'lib/labclient/lab_struct.rb', line 25
def inspect
@table.inspect
end
|
#key?(idx) ⇒ Boolean
54
55
56
|
# File 'lib/labclient/lab_struct.rb', line 54
def key?(idx)
@table.key? idx
end
|
#keys ⇒ Object
21
22
23
|
# File 'lib/labclient/lab_struct.rb', line 21
def keys
@table.keys.sort
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
50
51
52
|
# File 'lib/labclient/lab_struct.rb', line 50
def respond_to_missing?(method_name, include_private = false)
@table.keys.include?(method_name) || super
end
|
#slice(*opts) ⇒ Object
33
34
35
|
# File 'lib/labclient/lab_struct.rb', line 33
def slice(*opts)
@table.slice(*opts)
end
|
#success? ⇒ Boolean
42
43
44
|
# File 'lib/labclient/lab_struct.rb', line 42
def success?
@response.success?
end
|
#to_h ⇒ Object
17
18
19
|
# File 'lib/labclient/lab_struct.rb', line 17
def to_h
@table
end
|