Class: RelatonBib::TypedUri
Overview
Typed URI
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
- #language ⇒ String? readonly
- #script ⇒ String? readonly
- #type ⇒ String? readonly
Instance Method Summary collapse
-
#initialize(content:, type: nil, language: nil, script: nil) ⇒ TypedUri
constructor
A new instance of TypedUri.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Constructor Details
#initialize(content:, type: nil, language: nil, script: nil) ⇒ TypedUri
Returns a new instance of TypedUri.
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
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'lib/relaton_bib/typed_uri.rb', line 9 def content @content end |
#language ⇒ String? (readonly)
7 8 9 |
# File 'lib/relaton_bib/typed_uri.rb', line 7 def language @language end |
#script ⇒ String? (readonly)
7 8 9 |
# File 'lib/relaton_bib/typed_uri.rb', line 7 def script @script end |
#type ⇒ String? (readonly)
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
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_hash ⇒ 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
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 |