Class: LabClient::LabStruct

Inherits:
Object
  • Object
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

#responseObject (readonly)

Returns the value of attribute response.



7
8
9
# File 'lib/labclient/lab_struct.rb', line 7

def response
  @response
end

#tableObject (readonly)

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

#clientObject



37
38
39
# File 'lib/labclient/lab_struct.rb', line 37

def client
  response.client
end

#inspectObject



25
26
27
# File 'lib/labclient/lab_struct.rb', line 25

def inspect
  @table.inspect
end

#key?(idx) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/labclient/lab_struct.rb', line 54

def key?(idx)
  @table.key? idx
end

#keysObject



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

Returns:

  • (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

Forward response success

Returns:

  • (Boolean)


42
43
44
# File 'lib/labclient/lab_struct.rb', line 42

def success?
  @response.success?
end

#to_hObject



17
18
19
# File 'lib/labclient/lab_struct.rb', line 17

def to_h
  @table
end