Class: JsDuck::GroupedAsset
- Inherits:
-
Object
- Object
- JsDuck::GroupedAsset
- Defined in:
- lib/jsduck/grouped_asset.rb
Overview
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.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Accesses item by name.
-
#build_map_by_name(warning_msg) ⇒ Object
Should be called from constructor after @groups have been read in, and after it’s been ensured that all items in groupes have names.
-
#each_item ⇒ Object
Iterates over all items in all groups.
-
#to_array ⇒ Object
Returns all groups as array.
Instance Method Details
#[](name) ⇒ Object
Accesses item by name
31 32 33 |
# File 'lib/jsduck/grouped_asset.rb', line 31 def [](name) @map_by_name[name] end |
#build_map_by_name(warning_msg) ⇒ Object
Should be called from constructor after @groups have been read in, and after it’s been ensured that all items in groupes have names.
Prints warning when there is a duplicate item within a group. The warning message should say something like “duplicate <asset type>”
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jsduck/grouped_asset.rb', line 16 def build_map_by_name(warning_msg) @map_by_name = {} @groups.each do |group| group_map = {} group["items"].each do |item| if group_map[item["name"]] Logger.instance.warn(:dup_asset, "#{warning_msg} '#{item['name']}'") end @map_by_name[item["name"]] = item group_map[item["name"]] = item end end end |
#each_item ⇒ Object
Iterates over all items in all groups
36 37 38 39 40 |
# File 'lib/jsduck/grouped_asset.rb', line 36 def each_item @groups.each do |group| group["items"].each {|item| yield item } end end |
#to_array ⇒ Object
Returns all groups as array
43 44 45 |
# File 'lib/jsduck/grouped_asset.rb', line 43 def to_array @groups end |