Sha256: c1c5181cd2123d8e89f4e73def35fe6fca5cc7bf67be6983335e97448497d53c

Contents?: true

Size: 1.12 KB

Versions: 37

Compression:

Stored size: 1.12 KB

Contents

module Nexmo
  module OAS
    module Renderer
      module Presenters
        class Groups
          def initialize(definition)
            @definition = definition
          end

          def groups
            tags = @definition.raw['tags']
            # For now we only use the first tag in the list as an equivalent for the old x-group functionality
            @groups = @definition.endpoints.group_by do |endpoint|
              next nil unless tags
              endpoint.raw['tags']&.first
            end

            # We want to use the order in which the tags are defined in the definition, so iterate over the tags
            # and store the index against the tag name. We'll use this later for sorting
            ordering = {}
            tags&.each_with_index do |tag, index|
              ordering[tag['name'].capitalize] = index
            end

            # Sort by the order in which they're defined in the definition
            @groups = @groups.sort_by do |name, _|
              next -1 if name.nil?
              ordering[name.capitalize] || 999
            end
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
nexmo-oas-renderer-0.11.3 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.11.2 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.11.1 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.11.0 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.10.0 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.9.0 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.8.0 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.7.1 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.7.0 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.6.6 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.6.5 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.6.4 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.6.3 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.6.2 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.6.1 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.5.6 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.5.5 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.5.4 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.5.2 lib/nexmo/oas/renderer/presenters/groups.rb
nexmo-oas-renderer-0.5.1 lib/nexmo/oas/renderer/presenters/groups.rb