Class: Wikidata::Property::CommonsMedia
- Inherits:
-
Base
- Object
- Base
- Wikidata::Property::CommonsMedia
show all
- Defined in:
- lib/wikidata/property/commons_media.rb
Constant Summary
collapse
- BASE_PAGE_URL =
"https://commons.wikimedia.org/wiki/File:%s.%s".freeze
- IMAGE_URL =
"https://upload.wikimedia.org/wikipedia/commons/%s/%s/%s.%s"
- THUMB_IMAGE_URL =
"https://upload.wikimedia.org/wikipedia/commons/thumb/%s/%s/%s.%s/%ipx-%s.%s"
Instance Attribute Summary
Attributes inherited from Base
#property
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #value
Instance Method Details
#basename ⇒ Object
24
25
26
|
# File 'lib/wikidata/property/commons_media.rb', line 24
def basename
@_basename ||= name.gsub ' ', '_'
end
|
#extension ⇒ Object
36
37
38
|
# File 'lib/wikidata/property/commons_media.rb', line 36
def extension
@_ext ||= File.extname(value).tr '.', ''
end
|
#md5 ⇒ Object
20
21
22
|
# File 'lib/wikidata/property/commons_media.rb', line 20
def md5
@_md5 ||= Digest::MD5.hexdigest "#{basename}.#{extension}"
end
|
#name ⇒ Object
28
29
30
|
# File 'lib/wikidata/property/commons_media.rb', line 28
def name
@_name ||= File.basename(value, ".#{extension}")
end
|
#page_url ⇒ Object
8
9
10
|
# File 'lib/wikidata/property/commons_media.rb', line 8
def page_url
@_page_url ||= sprintf BASE_PAGE_URL, basename, extension
end
|
#thumb_extension ⇒ Object
32
33
34
|
# File 'lib/wikidata/property/commons_media.rb', line 32
def thumb_extension
@_thumb_ext ||= extension == 'svg' ? 'svg.png' : extension
end
|
#url(size = nil) ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/wikidata/property/commons_media.rb', line 12
def url size = nil
if size
sprintf THUMB_IMAGE_URL, md5[0], md5[0..1], basename, extension, size, basename, extension, thumb_extension
else
sprintf IMAGE_URL, md5[0], md5[0..1], basename, extension
end
end
|