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, language: nil, script: nil) ⇒ TypedUri

Returns a new instance of TypedUri.

Parameters:

  • content (String)

    URL

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

    src/obp/rss

  • language (String, nil) (defaults to: nil)

    language code Iso639 (optional) (default: nil)

  • script (String, nil) (defaults to: nil)

    script code Iso15924 (optional) (default: nil)



15
16
17
18
19
20
# File 'lib/relaton_bib/typed_uri.rb', line 15

def initialize(content:, type: nil, language: nil, script: nil)
  @type     = type
  @language = language
  @script   = script
  @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

#languageString? (readonly)

Returns:

  • (String, nil)


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

def language
  @language
end

#scriptString? (readonly)

Returns:

  • (String, nil)


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

def script
  @script
end

#typeString? (readonly)

Returns:

  • (String, nil)


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)


47
48
49
50
51
52
53
54
55
# File 'lib/relaton_bib/typed_uri.rb', line 47

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 += "#{pref}.language:: #{language}\n" if language
  out += "#{pref}.script:: #{script}\n" if script
  out
end

#to_hashHash

Returns:

  • (Hash)


36
37
38
39
40
41
42
# File 'lib/relaton_bib/typed_uri.rb', line 36

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

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


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

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