Class: WikipediaWrapper::WikiImage

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_info) ⇒ WikiImage

Returns a new instance of WikiImage.


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wikipedia_wrapper/image.rb', line 9

def initialize(raw_info)

  @small = nil
  @normal = nil

  if !raw_info.key?('imageinfo') || raw_info['imageinfo'].length != 1
    raise WikipediaWrapper::FormatError.new('WikiImage initialize', "Unknown format for imageinfo: #{raw_info}")
  end

  @filename = (raw_info.key? 'title') ? raw_info['title'].sub('File:', '') : 'No name'

  data = {
    'name': @filename,
    'mime': raw_info['imageinfo'][0]['mime'],
  }

  @description_url = raw_info['imageinfo'][0]['descriptionurl']

  @normal = Image.new(raw_info['imageinfo'][0]['url'],
                     raw_info['imageinfo'][0]['width'].to_i,
                     raw_info['imageinfo'][0]['height'].to_i, data)


  if raw_info['imageinfo'][0].key? ('thumburl')
    @small = Image.new(raw_info['imageinfo'][0]['thumburl'],
                             raw_info['imageinfo'][0]['thumbwidth'].to_i,
                             raw_info['imageinfo'][0]['thumbheight'].to_i,
                             data)
  else
    @small = @normal
  end

end

Instance Attribute Details

#description_urlObject

Returns the value of attribute description_url.


7
8
9
# File 'lib/wikipedia_wrapper/image.rb', line 7

def description_url
  @description_url
end

#normalObject

Returns the value of attribute normal.


7
8
9
# File 'lib/wikipedia_wrapper/image.rb', line 7

def normal
  @normal
end

#smallObject

Returns the value of attribute small.


7
8
9
# File 'lib/wikipedia_wrapper/image.rb', line 7

def small
  @small
end

Instance Method Details

#to_sObject


43
44
45
# File 'lib/wikipedia_wrapper/image.rb', line 43

def to_s
  "WikiImage #{@filename}"
end