Class: Gcloud::Vision::Image::Context::Area

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/vision/image.rb

Overview

# Image::Context::Area

A Lat/long rectangle that specifies the location of the image.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

image = vision.image "path/to/landmark.jpg"

image.context.area.min = { longitude: -122.0862462,
                           latitude: 37.4220041 }
image.context.area.max = { longitude: -122.0762462,
                           latitude: 37.4320041 }

entity = image.landmark

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeArea

Returns a new instance of Area.



514
515
516
517
# File 'lib/gcloud/vision/image.rb', line 514

def initialize
  @min = Location.new nil, nil
  @max = Location.new nil, nil
end

Instance Attribute Details

#maxLocation

Returns the max lat/long pair.

Returns:



510
511
512
# File 'lib/gcloud/vision/image.rb', line 510

def max
  @max
end

#minLocation

Returns the min lat/long pair.

Returns:



506
507
508
# File 'lib/gcloud/vision/image.rb', line 506

def min
  @min
end

Instance Method Details

#empty?Boolean

Returns ‘true` if either `min` or `max` are not populated.

Returns:

  • (Boolean)


556
557
558
559
# File 'lib/gcloud/vision/image.rb', line 556

def empty?
  min.to_hash.values.reject(&:nil?).empty? ||
    max.to_hash.values.reject(&:nil?).empty?
end

#to_gapiObject



579
580
581
582
583
584
585
# File 'lib/gcloud/vision/image.rb', line 579

def to_gapi
  return nil if empty?
  Google::Apis::VisionV1::LatLongRect.new(
    min_lat_lng: min.to_gapi,
    max_lat_lng: max.to_gapi
  )
end

#to_hHash

Deeply converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


566
567
568
# File 'lib/gcloud/vision/image.rb', line 566

def to_h
  to_hash
end

#to_hashHash

Deeply converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


575
576
577
# File 'lib/gcloud/vision/image.rb', line 575

def to_hash
  { min_lat_lng: min.to_hash, max_lat_lng: max.to_hash }
end