Class: LHC::Response::Data

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/lhc/response/data.rb

Defined Under Namespace

Modules: Base Classes: Collection, Item

Instance Method Summary collapse

Methods included from Base

#as_json, #as_open_struct

Constructor Details

#initialize(response, data: nil) ⇒ Data

Returns a new instance of Data.



10
11
12
13
14
15
16
17
18
19
# File 'lib/lhc/response/data.rb', line 10

def initialize(response, data: nil)
  @response = response
  @data = data

  if as_json.is_a?(Hash)
    @base = LHC::Response::Data::Item.new(@response, data: data)
  elsif as_json.is_a?(Array)
    @base = LHC::Response::Data::Collection.new(@response, data: data)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



21
22
23
# File 'lib/lhc/response/data.rb', line 21

def method_missing(method, *args, &block)
  @base.send(method, *args, &block)
end

Instance Method Details

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

Returns:

  • (Boolean)


25
26
27
# File 'lib/lhc/response/data.rb', line 25

def respond_to_missing?(method_name, include_private = false)
  @base.respond_to?(method_name, include_private) || super
end