Class: Gcloud::Vision::Annotation::Text::Word
- Inherits:
-
Object
- Object
- Gcloud::Vision::Annotation::Text::Word
- Defined in:
- lib/gcloud/vision/annotation/text.rb
Overview
# Word
A word within a detected text (OCR). See Gcloud::Vision::Annotation::Text.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#bounds ⇒ Array<Vertex>
The bounds of the word within the detected text.
-
#initialize ⇒ Word
constructor
A new instance of Word.
- #inspect ⇒ Object
-
#text ⇒ String
The text of the word.
-
#to_h ⇒ Hash
Deeply converts object to a hash.
-
#to_hash ⇒ Hash
Deeply converts object to a hash.
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize ⇒ Word
Returns a new instance of Word.
169 170 171 |
# File 'lib/gcloud/vision/annotation/text.rb', line 169 def initialize @gapi = {} end |
Instance Attribute Details
#gapi ⇒ Object
165 166 167 |
# File 'lib/gcloud/vision/annotation/text.rb', line 165 def gapi @gapi end |
Class Method Details
.from_gapi(gapi) ⇒ Object
229 230 231 |
# File 'lib/gcloud/vision/annotation/text.rb', line 229 def self.from_gapi gapi new.tap { |w| w.instance_variable_set :@gapi, gapi } end |
Instance Method Details
#bounds ⇒ Array<Vertex>
The bounds of the word within the detected text.
187 188 189 190 191 192 |
# File 'lib/gcloud/vision/annotation/text.rb', line 187 def bounds return [] unless @gapi.bounding_poly @bounds ||= Array(@gapi.bounding_poly.vertices).map do |v| Vertex.from_gapi v end end |
#inspect ⇒ Object
223 224 225 |
# File 'lib/gcloud/vision/annotation/text.rb', line 223 def inspect format "#<Word text: %s, bounds: %i>", text.inspect, bounds.count end |
#text ⇒ String
The text of the word.
178 179 180 |
# File 'lib/gcloud/vision/annotation/text.rb', line 178 def text @gapi.description end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
199 200 201 |
# File 'lib/gcloud/vision/annotation/text.rb', line 199 def to_h to_hash end |
#to_hash ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
208 209 210 |
# File 'lib/gcloud/vision/annotation/text.rb', line 208 def to_hash { text: text, bounds: bounds.map(&:to_h) } end |
#to_s ⇒ Object
213 214 215 |
# File 'lib/gcloud/vision/annotation/text.rb', line 213 def to_s to_str end |
#to_str ⇒ Object
218 219 220 |
# File 'lib/gcloud/vision/annotation/text.rb', line 218 def to_str text end |