Class: WikipediaWrapper::WikiImage
- Inherits:
-
Object
- Object
- WikipediaWrapper::WikiImage
- Defined in:
- lib/wikipedia_wrapper/image.rb
Instance Attribute Summary collapse
-
#description_url ⇒ Object
Returns the value of attribute description_url.
-
#normal ⇒ Object
Returns the value of attribute normal.
-
#small ⇒ Object
Returns the value of attribute small.
Instance Method Summary collapse
-
#initialize(raw_info) ⇒ WikiImage
constructor
A new instance of WikiImage.
- #to_s ⇒ Object
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_url ⇒ Object
Returns the value of attribute description_url.
7 8 9 |
# File 'lib/wikipedia_wrapper/image.rb', line 7 def description_url @description_url end |
#normal ⇒ Object
Returns the value of attribute normal.
7 8 9 |
# File 'lib/wikipedia_wrapper/image.rb', line 7 def normal @normal end |
#small ⇒ Object
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_s ⇒ Object
43 44 45 |
# File 'lib/wikipedia_wrapper/image.rb', line 43 def to_s "WikiImage #{@filename}" end |