Sha256: 93721b9157c28c45fd2c5e3a95077737c84d58cfa6ec2351b53513be970c6855
Contents?: true
Size: 1.19 KB
Versions: 22
Compression:
Stored size: 1.19 KB
Contents
require 'set' module Bourdain module Helpers class Registry attr_reader :name, :config def initialize @config = Hash.new { |default, key| default[key] = Set.new } end def register namespace, klass @config[namespace].add(klass) end def namespace namespace @config[namespace].to_a end def map namespace, &block @config[namespace].map(&block) end def specs namespace @config[namespace].map do |klass| Bourdain::Helpers::UsageParser.parse klass.raw_usage end end def klass namespace, name @config[namespace].select do |klass| Bourdain::Helpers::UsageParser.parse(klass.raw_usage)[:name] == name end.shift end def spec namespace, name specs(namespace).select do |spec| spec[:name] == name end.shift end def details namespace specs = specs(namespace) max_name_width = specs.sort_by { |s| s[:name].to_s.length }.last[:name].length max_name_width += 2 specs.map do |spec| "#{spec[:name].rjust(max_name_width)}: #{spec[:desc]}" end end end end end
Version data entries
22 entries across 22 versions & 1 rubygems