Class: Google::Search::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/google-search/item/web.rb,
lib/google-search/item/base.rb,
lib/google-search/item/blog.rb,
lib/google-search/item/book.rb,
lib/google-search/item/news.rb,
lib/google-search/item/image.rb,
lib/google-search/item/local.rb,
lib/google-search/item/video.rb,
lib/google-search/item/patent.rb

Direct Known Subclasses

Blog, Book, Image, Local, News, Patent, Video, Web

Defined Under Namespace

Classes: Blog, Book, Image, Local, News, Patent, Video, Web

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Item

Initialize with hash.



49
50
51
52
53
54
55
56
57
58
# File 'lib/google-search/item/base.rb', line 49

def initialize hash
  @index = hash['index']
  @title = hash['titleNoFormatting'] || hash['title']
  @uri = hash['unescapedUrl'] || hash['url'] || hash['postUrl']
  @content = hash['contentNoFormatting'] || hash['content']
  @thumbnail_uri = hash['tbUrl']
  @thumbnail_width = hash['tbWidth'].to_i
  @thumbnail_height = hash['tbHeight'].to_i
  @visible_uri = hash['visibleUrl']
end

Instance Attribute Details

#contentObject (readonly)

Contents.



44
45
46
# File 'lib/google-search/item/base.rb', line 44

def content
  @content
end

#indexObject (readonly)

Index.



9
10
11
# File 'lib/google-search/item/base.rb', line 9

def index
  @index
end

#thumbnail_heightObject (readonly)

Thumbnail height in pixels.



39
40
41
# File 'lib/google-search/item/base.rb', line 39

def thumbnail_height
  @thumbnail_height
end

#thumbnail_uriObject (readonly)

Thumbnail uri.



29
30
31
# File 'lib/google-search/item/base.rb', line 29

def thumbnail_uri
  @thumbnail_uri
end

#thumbnail_widthObject (readonly)

Thumbnail width in pixels.



34
35
36
# File 'lib/google-search/item/base.rb', line 34

def thumbnail_width
  @thumbnail_width
end

#titleObject (readonly)

Unformatted page title.



14
15
16
# File 'lib/google-search/item/base.rb', line 14

def title
  @title
end

#uriObject (readonly)

Absolute uri.



19
20
21
# File 'lib/google-search/item/base.rb', line 19

def uri
  @uri
end

#visible_uriObject (readonly)

Visible uri.



24
25
26
# File 'lib/google-search/item/base.rb', line 24

def visible_uri
  @visible_uri
end

Class Method Details

.class_for(google_class) ⇒ Object

Return class for google_class string formatted as ‘GwebSearch’, ‘GbookSearch’, etc.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/google-search/item/base.rb', line 64

def self.class_for google_class
  case google_class
  when 'GwebSearch'    ; Web
  when 'GlocalSearch'  ; Local
  when 'GbookSearch'   ; Book
  when 'GimageSearch'  ; Image
  when 'GvideoSearch'  ; Video
  when 'GpatentSearch' ; Patent
  when 'GnewsSearch'   ; News
  when 'GblogSearch'   ; Blog
  end
end