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.



8
9
10
11
12
13
14
# File 'lib/labclient/lab_struct.rb', line 8

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



45
46
47
# File 'lib/labclient/lab_struct.rb', line 45

def method_missing(method, *_args)
  @table[method] if @table.keys.include?(method)
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



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

def response
  @response
end

#tableObject (readonly)

Returns the value of attribute table.



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

def table
  @table
end

Instance Method Details

#[](name) ⇒ Object



61
62
63
# File 'lib/labclient/lab_struct.rb', line 61

def [](name)
  @table[name.to_sym]
end

#[]=(name, value) ⇒ Object



57
58
59
# File 'lib/labclient/lab_struct.rb', line 57

def []=(name, value)
  @table[name] = value
end

#as_json(*args) ⇒ Object



28
29
30
# File 'lib/labclient/lab_struct.rb', line 28

def as_json(*args)
  super.as_json['table']
end

#clientObject



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

def client
  response.client
end

#inspectObject



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

def inspect
  @table.inspect
end

#key?(idx) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#keysObject



20
21
22
# File 'lib/labclient/lab_struct.rb', line 20

def keys
  @table.keys.sort
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/labclient/lab_struct.rb', line 49

def respond_to_missing?(method_name, include_private = false)
  @table.keys.include?(method_name) || super
end

#slice(*opts) ⇒ Object



32
33
34
# File 'lib/labclient/lab_struct.rb', line 32

def slice(*opts)
  @table.slice(*opts)
end

#success?Boolean

Forward response success

Returns:

  • (Boolean)


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

def success?
  @response.success?
end

#to_hObject



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

def to_h
  @table
end