Skip to content

Commit

Permalink
add to_h method in objects
Browse files Browse the repository at this point in the history
  • Loading branch information
davilajose23 committed May 22, 2024
1 parent a1e0540 commit 99d4dd6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
unstructured (0.1.0)
unstructured (0.2.0)
faraday (~> 2.9.0)
faraday-multipart (~> 1.0.4)
marcel (~> 1.0.4)
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require "unstructured"

client = Unstructured::Client.new(
server_url: "http://localhost:8000",
api_key_auth: ENV["UNSTRUCTURED_API_KEY"]
# api_key_auth: ENV["UNSTRUCTURED_API_KEY"]
)

client.partition("./README.md")
Expand Down
7 changes: 7 additions & 0 deletions lib/unstructured/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
require "ostruct"
module Unstructured
class Object
attr_reader :attributes, :raw_data

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

Expand All @@ -16,5 +19,9 @@ def method_missing(method, *args, &block)
def respond_to_missing?(_method, _include_private = false)
true
end

def to_h
@raw_data
end
end
end
2 changes: 1 addition & 1 deletion lib/unstructured/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Unstructured
VERSION = "0.1.1"
VERSION = "0.2.0"
end
4 changes: 4 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@
expect(client.partition("spec/fixtures/sample.pdf").first.metadata.filetype).to eq(stub_filetype)
expect(client.partition("spec/fixtures/sample.pdf").first.metadata.filename).to eq(stub_filename)
end

it "should return a hash when using to_h" do
expect(client.partition("spec/fixtures/sample.pdf").first.to_h).to be_a(Hash)
end
end
end

0 comments on commit 99d4dd6

Please sign in to comment.