Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

New instance variable @raw for extractions. #2

Merged
merged 1 commit into from
Mar 14, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ doc.extractions[:amountToPay] # Shortcut to get extraction value
# => "10.00:EUR"
doc.extractions.candidates[:dates]
# => Array of all found candidates
doc.extractions.raw
# => {:extractions=>{...
```

### Submitting feedback
Expand Down
5 changes: 5 additions & 0 deletions lib/gini-api/document/extractions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Api
#
class Document::Extractions

attr_reader :raw

# Instantiate a new Gini::Api::Extractions object from hash
#
# @param [Gini::Api::Client] api Gini::Api::Client object
Expand All @@ -28,6 +30,9 @@ def update
)
end

# Entire response
@raw = response.parsed

response.parsed[:extractions].each do |k,v|
instance_variable_set("@#{k}", v)
self.class.send(:attr_reader, k)
Expand Down
6 changes: 6 additions & 0 deletions spec/gini-api/document/extraction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

it { should respond_to(:update) }
it { should respond_to(:[]) }
it { should respond_to(:raw) }

describe '#update' do

Expand All @@ -78,6 +79,11 @@
extractions.update
end

it 'saves raw response' do
expect(extractions.raw).to eql(JSON.parse(response.body, symbolize_names: true))
extractions.update
end

context 'failed extraction fetch' do

let(:response) { double('Response', :status => 404, env: {}, body: {}) }
Expand Down