Sha256: b33e1d25850863eb67c546941beb507e4e1f82d6d25a50817c9ba475fee959bb

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

require 'hyperclient/resource'

module Hyperclient
  # Internal: Curies are named tokens that you can define in the document and use
  # to express curie relation URIs in a friendlier, more compact fashion.
  #
  class Curie
    # Public: Initializes a new Curie.
    #
    # curie_hash  - The String with the URI of the curie.
    # entry_point - The EntryPoint object to inject the configuration.
    def initialize(curie_hash, entry_point)
      @curie_hash = curie_hash
      @entry_point = entry_point
    end

    # Public: Indicates if the curie is an URITemplate or a regular URI.
    #
    # Returns true if it is templated.
    # Returns false if it not templated.
    def templated?
      !!@curie_hash['templated']
    end

    # Public: Returns the name property of the Curie.
    def name
      @curie_hash['name']
    end

    # Public: Returns the href property of the Curie.
    def href
      @curie_hash['href']
    end

    def inspect
      "#<#{self.class.name} #{@curie_hash}>"
    end

    # Public: Expands the Curie when is templated with the given variables.
    #
    # rel - The String rel to expand.
    #
    # Returns a new expanded url.
    def expand(rel)
      return rel unless rel && templated?
      href.gsub('{rel}', rel) if href
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hyperclient-0.8.1 lib/hyperclient/curie.rb
hyperclient-0.8.0 lib/hyperclient/curie.rb
hyperclient-0.7.2 lib/hyperclient/curie.rb
hyperclient-0.7.1 lib/hyperclient/curie.rb