Class: Google::Cloud::Vision::Annotation::Text::Word
- Inherits:
-
Object
- Object
- Google::Cloud::Vision::Annotation::Text::Word
- Defined in:
- lib/google/cloud/vision/annotation/text.rb
Overview
# Word
A word within a detected text (OCR). See Google::Cloud::Vision::Annotation::Text.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.from_grpc(grpc) ⇒ Object
object.
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_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize ⇒ Word
Returns a new instance of Word.
160 161 162 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 160 def initialize @grpc = nil end |
Instance Attribute Details
#grpc ⇒ Object
156 157 158 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 156 def grpc @grpc end |
Class Method Details
.from_grpc(grpc) ⇒ Object
object.
212 213 214 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 212 def self.from_grpc grpc new.tap { |w| w.instance_variable_set :@grpc, grpc } end |
Instance Method Details
#bounds ⇒ Array<Vertex>
The bounds of the word within the detected text.
178 179 180 181 182 183 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 178 def bounds return [] unless @grpc.bounding_poly @bounds ||= Array(@grpc.bounding_poly.vertices).map do |v| Vertex.from_grpc v end end |
#inspect ⇒ Object
205 206 207 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 205 def inspect format "#<Word text: %s, bounds: %i>", text.inspect, bounds.count end |
#text ⇒ String
The text of the word.
169 170 171 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 169 def text @grpc.description end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
190 191 192 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 190 def to_h { text: text, bounds: bounds.map(&:to_h) } end |
#to_s ⇒ Object
195 196 197 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 195 def to_s to_str end |
#to_str ⇒ Object
200 201 202 |
# File 'lib/google/cloud/vision/annotation/text.rb', line 200 def to_str text end |