Sha256: 3164a1fb37f24dccdc196a7816da63c7fd6d53744d6d7a12bf67dc3eeaa4bc02

Contents?: true

Size: 1.02 KB

Versions: 29

Compression:

Stored size: 1.02 KB

Contents

module GoodData
  class Links
    attr_reader :data

    def initialize(items)
      @data = {}
      items.values[0]['links'].each do |item|
        category = item['category']
        if @data[category] then
          if @data[category]['category'] == category then
            @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(GoodData.get(self[category])) unless identifier
      Links.new GoodData.get(get(category, identifier))
    end

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

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

    def is_ambiguous?(category)
      !is_unique?(category)
    end

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

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
gooddata-0.5.6 lib/gooddata/models/links.rb
gooddata-0.5.5 lib/gooddata/models/links.rb
gooddata-0.5.4 lib/gooddata/models/links.rb
gooddata-0.5.3 lib/gooddata/models/links.rb
gooddata-0.5.2 lib/gooddata/models/links.rb
gooddata-0.5.1 lib/gooddata/models/links.rb
gooddata-0.5.0 lib/gooddata/models/links.rb
gooddata-0.4.0 lib/gooddata/models/links.rb
gooddata-0.2.0 lib/gooddata/models/links.rb