class JsDuck::GroupedAsset
Parent class for assets that consist of groups. That is: guides, vides, examples.
Subclasses must initialize @groups before calling any of the methods in this class.
Public Instance Methods
[](name)
click to toggle source
Accesses item by name
# File lib/jsduck/grouped_asset.rb, line 21 def [](name) @map_by_name[name] end
build_map_by_name()
click to toggle source
Should be called from constructor after @groups have been read in, and after it's been ensured that all items in groupes have names.
# File lib/jsduck/grouped_asset.rb, line 13 def build_map_by_name @map_by_name = {} each_item do |item| @map_by_name[item["name"]] = item end end
each_item(group=nil, &block)
click to toggle source
Iterates over all items in all groups
# File lib/jsduck/grouped_asset.rb, line 26 def each_item(group=nil, &block) group = group || @groups group.each do |item| if item["items"] each_item(item["items"], &block) else block.call(item) end end end
map_items(group=nil, &block)
click to toggle source
# File lib/jsduck/grouped_asset.rb, line 38 def map_items(group=nil, &block) group = group || @groups group.map do |item| if item["items"] { "title" => item["title"], "items" => map_items(item["items"], &block) } else block.call(item) end end end
to_array()
click to toggle source
Returns all groups as array
# File lib/jsduck/grouped_asset.rb, line 54 def to_array @groups end