Module: Gamesdb::Utils

Defined in:
lib/thegamesdb/utils.rb

Overview

Several reusable functions

Class Method Summary collapse

Class Method Details

.art_structure(art, width, height) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/thegamesdb/utils.rb', line 36

def art_structure(art, width, height)
  {
    url: art['filename'],
    resolution: art['resolution'],
    width: width,
    height: height
  }
end

.build_individual_fanart(art) ⇒ Object



31
32
33
34
# File 'lib/thegamesdb/utils.rb', line 31

def build_individual_fanart(art)
  width, height = art['resolution'].split('x') unless art['resolution'].nil?
  art_structure(art, width, height)
end

.process_covers(data, id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/thegamesdb/utils.rb', line 19

def process_covers(data, id)
  covers = {}
  boxart = select_images(data, id, 'boxart')
  return [] if boxart.empty?

  boxart.each do |art|
    width, height = art['resolution'].split('x') unless art['resolution'].nil?
    covers[art['side'].to_sym] = art_structure(art, width, height)
  end
  covers
end

.process_fanart(data, id) ⇒ Object



12
13
14
15
16
17
# File 'lib/thegamesdb/utils.rb', line 12

def process_fanart(data, id)
  fanart = select_images(data, id, 'fanart')
  return [] if fanart.empty?

  fanart.map { |art| build_individual_fanart(art) }
end

.process_logo(data, id) ⇒ Object



7
8
9
10
# File 'lib/thegamesdb/utils.rb', line 7

def (data, id)
   = data['images'][id.to_s].select { |a| a['type'] == 'clearlogo' }
  .empty? ? '' : .first['filename']
end

.process_screenshots(data, id) ⇒ Object



45
46
47
48
49
# File 'lib/thegamesdb/utils.rb', line 45

def process_screenshots(data, id)
  select_images(data, id, 'screenshot').map do |b|
    Gamesdb::Utils.symbolize_keys(b)
  end
end

.select_images(data, id, image_type) ⇒ Object



51
52
53
54
55
# File 'lib/thegamesdb/utils.rb', line 51

def select_images(data, id, image_type)
  data['images'][id.to_s].select do |a|
    a['type'] == image_type
  end
end

.symbolize_keys(hash) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/thegamesdb/utils.rb', line 57

def symbolize_keys(hash)
  new_hash = {}
  hash.each_key do |key|
    new_hash[key.to_sym] = hash.delete(key)
  end
  new_hash
end