Class: Halibut::LinkRelation

Inherits:
Object
  • Object
show all
Defined in:
lib/halibut/link_relation.rb

Overview

Domain object that represents a Relation

spec spec spec.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ LinkRelation

Initialize a `LinkRelation`. A LinkRelation can be one of the relations registered, or use the CURIE syntax to introduce a custom namespace. This syntax is introduced by using the separator `:`.

Examples:

Simple LinkRelation

Halibut::LinkRelation.new("author")

CURIE syntax LinkRelation

Halibut::LinkRelation.new("twitter:tweet")

Parameters:

  • name (String)

    Name of the relation, with possible CURIE syntax.


21
22
23
24
25
# File 'lib/halibut/link_relation.rb', line 21

def initialize(name)
  splits = name.to_s.split(":")

  splits.size < 2 ? @name = splits.first : (@curie, @name = splits)
end

Instance Attribute Details

#curieObject

Returns the value of attribute curie


7
8
9
# File 'lib/halibut/link_relation.rb', line 7

def curie
  @curie
end

#nameObject

Returns the value of attribute name


7
8
9
# File 'lib/halibut/link_relation.rb', line 7

def name
  @name
end

Instance Method Details

#eql?(other) ⇒ Boolean

Compares two `LinkRelation`s.

Examples:

one = Halibut::LinkRelation.new('lol')
two = Halibut::LinkRelation.new('lol')
one.eql?(two)
# => true

Parameters:

Returns:

  • (Boolean)

36
37
38
# File 'lib/halibut/link_relation.rb', line 36

def eql?(other)
  hash == other.hash
end

#hashObject


40
41
42
# File 'lib/halibut/link_relation.rb', line 40

def hash
  instance_variables.hash
end

#to_sString

Returns a custom formatted string representation of the object.

Examples:

Basic link relation

Halibut::LinkRelation.new('lol').to_s
# => "lol"

Link relation with CURIE

Halibut::LinkRelation.new('cs:lol').to_s
# => "cs:lol"

Returns:

  • (String)

    name of the relation, optionally containing CURIE


55
56
57
# File 'lib/halibut/link_relation.rb', line 55

def to_s
  @curie and "#{@curie}:#{@name}" or @name
end