Sha256: dd14c5b2ac4ee89af3313dac1188433a7da08d58560f2d74174a14df8adf50be

Contents?: true

Size: 1.26 KB

Versions: 26

Compression:

Stored size: 1.26 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2015 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

require_relative '../rest/object'

module GoodData
  class Links < Rest::Resource
    attr_reader :data

    def initialize(items)
      @data = {}
      items.values[0]['links'].each do |item|
        category = item['category']
        if @data[category]
          if @data[category]['category'] == category
            @data[category] = { @data[category]['identifier'] => @data[category] }
          end
          @data[category][item['identifier']] = item
        else
          @data[category] = item
        end
      end
    end

    def links(category, identifier = nil)
      return Links.new(client.get(self[category])) unless identifier
      Links.new client.get(get(category, identifier))
    end

    def [](category)
      return @data[category]['link'] if @data[category] && @data[category]['link']
      @data[category]
    end

    def unique?(category)
      @data[category]['link'].is_a? String
    end

    def ambiguous?(category)
      !unique?(category)
    end

    def get(category, identifier)
      self[category][identifier]
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
gooddata-edge-0.6.27.edge lib/gooddata/models/links.rb
gooddata-0.6.49 lib/gooddata/models/links.rb
gooddata-0.6.48 lib/gooddata/models/links.rb
gooddata-0.6.47 lib/gooddata/models/links.rb
gooddata-0.6.46 lib/gooddata/models/links.rb
gooddata-0.6.45 lib/gooddata/models/links.rb
gooddata-0.6.44 lib/gooddata/models/links.rb
gooddata-0.6.43 lib/gooddata/models/links.rb
gooddata-0.6.42 lib/gooddata/models/links.rb
gooddata-0.6.41 lib/gooddata/models/links.rb
gooddata-0.6.40 lib/gooddata/models/links.rb
gooddata-0.6.39 lib/gooddata/models/links.rb
gooddata-0.6.38 lib/gooddata/models/links.rb
gooddata-0.6.37 lib/gooddata/models/links.rb
gooddata-0.6.36 lib/gooddata/models/links.rb
gooddata-0.6.35 lib/gooddata/models/links.rb
gooddata-0.6.34 lib/gooddata/models/links.rb
gooddata-0.6.33 lib/gooddata/models/links.rb
gooddata-0.6.32 lib/gooddata/models/links.rb
gooddata-0.6.31 lib/gooddata/models/links.rb