Sha256: 9b4db79ce252b26523871e4f55e78c901cb8867d06143d2d2e549c2b19df8681

Contents?: true

Size: 1.25 KB

Versions: 52

Compression:

Stored size: 1.25 KB

Contents

require 'jsduck/logger'

module JsDuck

  # 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.
  class GroupedAsset
    # Should be called from constructor after @groups have been read in,
    # and after it's been ensured that all items in groupes have names.
    def build_map_by_name
      @map_by_name = {}
      each_item do |item|
        @map_by_name[item["name"]] = item
      end
    end

    # Accesses item by name
    def [](name)
      @map_by_name[name]
    end

    # Iterates over all items in all groups
    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

    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

    # Returns all groups as array
    def to_array
      @groups
    end
  end

end

Version data entries

52 entries across 52 versions & 3 rubygems

Version Path
solvas-jsduck-6.0.0.30539 lib/jsduck/grouped_asset.rb
solvas-jsduck-6.0.0.9571 lib/jsduck/grouped_asset.rb
solvas-jsduck-6.0.0.6154 lib/jsduck/grouped_asset.rb
solvas-jsduck-6.0.0.4021 lib/jsduck/grouped_asset.rb
solvas-jsduck-6.0.0.2554 lib/jsduck/grouped_asset.rb
solvas-jsduck-6.0.0.1891 lib/jsduck/grouped_asset.rb
solvas-jsduck-6.0.0.beta.1888 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.10 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.9 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.8 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.7 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.5 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.4 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.3 lib/jsduck/grouped_asset.rb
jsduck-troopjs-0.0.1 lib/jsduck/grouped_asset.rb
jsduck-6.0.0beta lib/jsduck/grouped_asset.rb
jsduck-5.3.4 lib/jsduck/grouped_asset.rb
jsduck-5.3.3 lib/jsduck/grouped_asset.rb
jsduck-5.3.2 lib/jsduck/grouped_asset.rb
jsduck-5.3.1 lib/jsduck/grouped_asset.rb