Class: Desiru::ModuleResult

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/desiru/module.rb

Overview

Result object for module outputs

Direct Known Subclasses

ProgramResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil, metadata: {}, **kwargs) ⇒ ModuleResult

Returns a new instance of ModuleResult.



201
202
203
204
205
206
207
208
209
210
211
# File 'lib/desiru/module.rb', line 201

def initialize(data = nil, metadata: {}, **kwargs)
  # Support both positional and keyword arguments for backward compatibility
  if data.nil? && !kwargs.empty?
    @data = kwargs
    @outputs = kwargs
  else
    @data = data || {}
    @outputs = @data
  end
  @metadata = 
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/desiru/module.rb', line 227

def method_missing(method_name, *args, &)
  method_str = method_name.to_s
  if method_str.end_with?('?')
    # Handle predicate methods for boolean values
    key = method_str[0..-2].to_sym
    if data.key?(key)
      return !!data[key]
    elsif data.key?(key.to_s)
      return !!data[key.to_s]
    end
  end

  if data.key?(method_name.to_sym)
    data[method_name.to_sym]
  elsif data.key?(method_name.to_s)
    data[method_name.to_s]
  else
    super
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



197
198
199
# File 'lib/desiru/module.rb', line 197

def data
  @data
end

#metadataObject (readonly)

Returns the value of attribute metadata.



197
198
199
# File 'lib/desiru/module.rb', line 197

def 
  @metadata
end

#outputsObject (readonly)

Returns the value of attribute outputs.



197
198
199
# File 'lib/desiru/module.rb', line 197

def outputs
  @outputs
end

Instance Method Details

#[](key) ⇒ Object



213
214
215
216
217
218
219
# File 'lib/desiru/module.rb', line 213

def [](key)
  if @data.key?(key.to_sym)
    @data[key.to_sym]
  elsif @data.key?(key.to_s)
    @data[key.to_s]
  end
end

#key?(key) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


221
222
223
# File 'lib/desiru/module.rb', line 221

def key?(key)
  @data.key?(key.to_sym) || @data.key?(key.to_s)
end

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

Returns:

  • (Boolean)


248
249
250
251
252
253
254
255
256
# File 'lib/desiru/module.rb', line 248

def respond_to_missing?(method_name, include_private = false)
  method_str = method_name.to_s
  if method_str.end_with?('?')
    key = method_str[0..-2]
    data.key?(key.to_sym) || data.key?(key)
  else
    data.key?(method_name.to_sym) || data.key?(method_name.to_s) || super
  end
end

#to_hObject



258
259
260
# File 'lib/desiru/module.rb', line 258

def to_h
  data
end