lib/google/cloud/vision/annotation/properties.rb in google-cloud-vision-0.20.2 vs lib/google/cloud/vision/annotation/properties.rb in google-cloud-vision-0.21.0
- old
+ new
@@ -24,40 +24,39 @@
# colors.
#
# See {Google::Cloud::Vision::Image#properties}.
#
# @example
- # require "google/cloud"
+ # require "google/cloud/vision"
#
- # gcloud = Google::Cloud.new
- # vision = gcloud.vision
+ # vision = Google::Cloud::Vision.new
#
# image = vision.image "path/to/logo.jpg"
#
# properties = image.properties
# properties.colors.count #=> 10
#
class Properties
##
- # @private The ImageProperties Google API Client object.
- attr_accessor :gapi
+ # @private The ImageProperties GRPC object.
+ attr_accessor :grpc
##
# @private Creates a new Properties instance.
def initialize
- @gapi = {}
+ @grpc = nil
end
##
# The image's dominant colors, including their corresponding scores.
#
# @return [Array<Color>] An array of the image's dominant colors.
#
def colors
- return [] unless @gapi.dominant_colors
- @colors ||= Array(@gapi.dominant_colors.colors).map do |c|
- Color.from_gapi c
+ return [] unless @grpc.dominant_colors
+ @colors ||= Array(@grpc.dominant_colors.colors).map do |c|
+ Color.from_grpc c
end
end
##
# Returns the object's property values as an array.
@@ -86,26 +85,25 @@
def inspect
"#<Properties #{self}>"
end
##
- # @private New Annotation::Properties from a Google API Client object.
- def self.from_gapi gapi
- new.tap { |f| f.instance_variable_set :@gapi, gapi }
+ # @private New Annotation::Properties from a GRPC object.
+ def self.from_grpc grpc
+ new.tap { |f| f.instance_variable_set :@grpc, grpc }
end
##
# # Color
#
# Color information consisting of RGB channels, score, and fraction of
# image the color occupies in the image.
#
# @example
- # require "google/cloud"
+ # require "google/cloud/vision"
#
- # gcloud = Google::Cloud.new
- # vision = gcloud.vision
+ # vision = Google::Cloud::Vision.new
#
# image = vision.image "path/to/logo.jpg"
# properties = image.properties
#
# color = properties.colors.first
@@ -117,55 +115,55 @@
# color.score #=> 0.20301804
# color.pixel_fraction #=> 0.0072649573
#
class Color
##
- # @private The ColorInfo Google API Client object.
- attr_accessor :gapi
+ # @private The ColorInfo GRPC object.
+ attr_accessor :grpc
##
# @private Creates a new Color instance.
def initialize
- @gapi = {}
+ @grpc = nil
end
##
# The amount of red in the color.
#
# @return [Float] A value in the interval [0, 255].
#
def red
- @gapi.color.red
+ @grpc.color.red
end
##
# The amount of green in the color.
#
# @return [Float] A value in the interval [0, 255].
#
def green
- @gapi.color.green
+ @grpc.color.green
end
##
# The amount of blue in the color.
#
# @return [Float] A value in the interval [0, 255].
#
def blue
- @gapi.color.blue
+ @grpc.color.blue
end
##
# The amount this color that should be applied to the pixel. A value
# of 1.0 corresponds to a solid color, whereas a value of 0.0
# corresponds to a completely transparent color.
#
# @return [Float] A value in the range [0, 1].
#
def alpha
- @gapi.color.alpha || 1.0
+ @grpc.color.alpha || 1.0
end
def rgb
red.to_i.to_s(16).rjust(2, "0") +
green.to_i.to_s(16).rjust(2, "0") +
@@ -176,20 +174,20 @@
# Image-specific score for this color.
#
# @return [Float] A value in the range [0, 1].
#
def score
- @gapi.score
+ @grpc.score
end
##
# Stores the fraction of pixels the color occupies in the image.
#
# @return [Float] A value in the range [0, 1].
#
def pixel_fraction
- @gapi.pixel_fraction
+ @grpc.pixel_fraction
end
##
# Converts object to a hash. All keys will be symbolized.
#
@@ -207,13 +205,13 @@
def inspect
"#<Color #{self}>"
end
##
- # @private New Annotation::Properties from a Google API Client
+ # @private New Annotation::Properties from a GRPC
# object.
- def self.from_gapi gapi
- new.tap { |f| f.instance_variable_set :@gapi, gapi }
+ def self.from_grpc grpc
+ new.tap { |f| f.instance_variable_set :@grpc, grpc }
end
end
end
end
end