Class: Unstructured::Object

Inherits:
Object
  • Object
show all
Defined in:
lib/unstructured/object.rb

Direct Known Subclasses

Chunk

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Object

Returns a new instance of Object.



8
9
10
11
# File 'lib/unstructured/object.rb', line 8

def initialize(attributes)
  @raw_data = attributes
  @attributes = OpenStruct.new(attributes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



13
14
15
16
17
# File 'lib/unstructured/object.rb', line 13

def method_missing(method, *args, &block)
  method = method.to_s
  attribute = @attributes.send(method, *args, &block)
  attribute.is_a?(Hash) ? Object.new(attribute) : attribute
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



6
7
8
# File 'lib/unstructured/object.rb', line 6

def attributes
  @attributes
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



6
7
8
# File 'lib/unstructured/object.rb', line 6

def raw_data
  @raw_data
end

Instance Method Details

#respond_to_missing?(_method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/unstructured/object.rb', line 19

def respond_to_missing?(_method, _include_private = false)
  true
end

#to_hObject



23
24
25
# File 'lib/unstructured/object.rb', line 23

def to_h
  @raw_data
end