Class: RelatonBib::TypedUri

Inherits:
Object show all
Defined in:
lib/relaton_bib/typed_uri.rb

Overview

Typed URI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, type: nil) ⇒ TypedUri

Returns a new instance of TypedUri.

Parameters:

  • type (String, NilClass) (defaults to: nil)

    src/obp/rss

  • content (String)


13
14
15
16
# File 'lib/relaton_bib/typed_uri.rb', line 13

def initialize(content:, type: nil)
  @type    = type
  @content = Addressable::URI.parse content if content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/relaton_bib/typed_uri.rb', line 9

def content
  @content
end

#typeSymbol (readonly)

Returns :src/:obp/:rss.

Returns:

  • (Symbol)

    :src/:obp/:rss



7
8
9
# File 'lib/relaton_bib/typed_uri.rb', line 7

def type
  @type
end

Instance Method Details

#to_asciibib(prefix = "", count = 1) ⇒ String

Parameters:

  • prefix (String) (defaults to: "")
  • count (Integer) (defaults to: 1)

    number of links

Returns:

  • (String)


39
40
41
42
43
44
45
# File 'lib/relaton_bib/typed_uri.rb', line 39

def to_asciibib(prefix = "", count = 1)
  pref = prefix.empty? ? "link" : prefix + ".link"
  out = count > 1 ? "#{pref}::\n" : ""
  out += "#{pref}.type:: #{type}\n" if type
  out += "#{pref}.content:: #{content}\n"
  out
end

#to_hashHash

Returns:

  • (Hash)


30
31
32
33
34
# File 'lib/relaton_bib/typed_uri.rb', line 30

def to_hash
  hash = { "content" => content.to_s }
  hash["type"] = type.to_s if type
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


24
25
26
27
# File 'lib/relaton_bib/typed_uri.rb', line 24

def to_xml(builder)
  doc = builder.uri content.to_s
  doc[:type] = type if type
end