Class: Gini::Api::Document::Extractions
- Inherits:
-
Object
- Object
- Gini::Api::Document::Extractions
- Defined in:
- lib/gini-api/document/extractions.rb
Overview
Contains document related extractions
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#[](item) ⇒ String, Integer
Get filed value for given extraction key.
-
#initialize(api, location) ⇒ Extractions
constructor
Instantiate a new Gini::Api::Extractions object from hash.
-
#update ⇒ Object
Populate instance variables from fetched extractions.
Constructor Details
#initialize(api, location) ⇒ Extractions
Instantiate a new Gini::Api::Extractions object from hash
14 15 16 17 18 19 |
# File 'lib/gini-api/document/extractions.rb', line 14 def initialize(api, location) @api = api @location = location update end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
8 9 10 |
# File 'lib/gini-api/document/extractions.rb', line 8 def raw @raw end |
Instance Method Details
#[](item) ⇒ String, Integer
Get filed value for given extraction key
50 51 52 53 54 55 56 |
# File 'lib/gini-api/document/extractions.rb', line 50 def [](item) unless instance_variable_get("@#{item}") raise Gini::Api::DocumentError.new("Invalid extraction key #{item}: Not found") end instance_variable_get("@#{item}")[:value] end |
#update ⇒ Object
Populate instance variables from fetched extractions
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gini-api/document/extractions.rb', line 23 def update response = @api.request(:get, @location) unless response.status == 200 raise Gini::Api::DocumentError.new( "Failed to fetch extractions from #{@location}", response ) end # Entire response @raw = response.parsed response.parsed[:extractions].each do |k,v| instance_variable_set("@#{k}", v) self.class.send(:attr_reader, k) end instance_variable_set("@candidates", response.parsed[:candidates]) self.class.send(:attr_reader, :candidates) end |