Sha256: 80693753ef316ee4981ed5ac07c2a9bde132f215cc06e975d0d317475222b86c

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

# encoding: UTF-8

require_relative '../rest/object'

module GoodData
  class Links < GoodData::Rest::Object
    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

13 entries across 13 versions & 1 rubygems

Version Path
gooddata-0.6.20 lib/gooddata/models/links.rb
gooddata-0.6.19 lib/gooddata/models/links.rb
gooddata-0.6.18 lib/gooddata/models/links.rb
gooddata-0.6.17 lib/gooddata/models/links.rb
gooddata-0.6.16 lib/gooddata/models/links.rb
gooddata-0.6.15 lib/gooddata/models/links.rb
gooddata-0.6.14 lib/gooddata/models/links.rb
gooddata-0.6.13 lib/gooddata/models/links.rb
gooddata-0.6.12 lib/gooddata/models/links.rb
gooddata-0.6.11 lib/gooddata/models/links.rb
gooddata-0.6.10 lib/gooddata/models/links.rb
gooddata-0.6.9 lib/gooddata/models/links.rb
gooddata-0.6.8 lib/gooddata/models/links.rb