Class: Google::Search::Image

Inherits:
Google::Search show all
Includes:
SafetyLevel
Defined in:
lib/google-search/search/image.rb

Constant Summary collapse

SIZES =

– Constants ++

:icon, :small, :medium, :large, :xlarge, :xxlarge, :huge
TYPES =
:face, :photo, :clipart, :lineart
EXTENSIONS =
:jpg, :png, :gif, :bmp

Constants included from SafetyLevel

SafetyLevel::SAFETY_LEVELS

Constants inherited from Google::Search

URI, VERSION

Instance Attribute Summary collapse

Attributes included from SafetyLevel

#safety_level

Attributes inherited from Google::Search

#api_key, #language, #offset, #options, #query, #sent, #size, #type, #version

Instance Method Summary collapse

Methods inherited from Google::Search

#all_items, #each_item, #each_response, #get_hash, #get_raw, #get_response, #get_uri, json_decode, #next, size_for, url_encode, #validate

Constructor Details

#initialize(options = {}, &block) ⇒ Image

:nodoc:


68
69
70
71
72
73
74
# File 'lib/google-search/search/image.rb', line 68

def initialize options = {}, &block
  @color = options.delete :color
  @image_size = options.delete :image_size
  @image_type = options.delete :image_type
  @file_type = options.delete :file_type
  super
end

Instance Attribute Details

#colorObject

Image color.


59
60
61
# File 'lib/google-search/search/image.rb', line 59

def color
  @color
end

#file_typeObject

File type:

- :jpg
- :gif
- :png
- :bmp

54
55
56
# File 'lib/google-search/search/image.rb', line 54

def file_type
  @file_type
end

#image_sizeObject

Image size:

- :icon
- :small
- :medium
- :large
- :xlarge
- :xxlarge
- :huge

32
33
34
# File 'lib/google-search/search/image.rb', line 32

def image_size
  @image_size
end

#image_typeObject

Image type:

- :face
- :photo
- :clipart
- :lineart

43
44
45
# File 'lib/google-search/search/image.rb', line 43

def image_type
  @image_type
end

#uriObject

Specific uri to fetch images from.


64
65
66
# File 'lib/google-search/search/image.rb', line 64

def uri
  @uri
end

Instance Method Details

#get_uri_paramsObject

:nodoc:


78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/google-search/search/image.rb', line 78

def get_uri_params
  validate(:image_size) { |size| size.nil? || size.is_a?(Array) || SIZES.include?(size) }
  validate(:image_type) { |type| type.nil? || TYPES.include?(type) }
  validate(:file_type) { |ext| ext.nil? || EXTENSIONS.include?(ext) }
  super + [
    [:safe, safety_level],
    [:imgsz, image_size.is_a?(Array) ? image_size.join('|') : image_size],
    [:imgcolor, color],
    [:imgtype, image_type],
    [:as_filetype, file_type],
    [:as_sitesearch, uri]
    ]
end