Class: JsDuck::Videos

Inherits:
GroupedAsset show all
Defined in:
lib/jsduck/videos.rb

Overview

Reads in videos JSON file

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GroupedAsset

#[], #build_map_by_name, #each_item, #map_items, #to_array

Constructor Details

#initialize(filename) ⇒ Videos

Returns a new instance of Videos.



18
19
20
21
22
# File 'lib/jsduck/videos.rb', line 18

def initialize(filename)
  @groups = Util::Json.read(filename)
  add_names_if_missing
  build_map_by_name
end

Class Method Details

.create(filename) ⇒ Object

Parses videos config file



10
11
12
13
14
15
16
# File 'lib/jsduck/videos.rb', line 10

def self.create(filename)
  if filename
    Videos.new(filename)
  else
    Util::NullObject.new(:to_array => [], :[] => nil)
  end
end

Instance Method Details

#add_names_if_missingObject

Each video should have a name, which is used in URL to reference the video. For backwards compatibility, when name is missing, we turn the “id” (that must exist) into a name.



27
28
29
30
31
# File 'lib/jsduck/videos.rb', line 27

def add_names_if_missing
  each_item do |video|
    video["name"] = video["id"] unless video["name"]
  end
end

#icon_url(video) ⇒ Object

Extracts video icon URL from video hash



34
35
36
# File 'lib/jsduck/videos.rb', line 34

def icon_url(video)
  video["thumb"]
end