Class: RelatonBib::TypedUri
Overview
Typed URI
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#type ⇒ Symbol
readonly
:src/:obp/:rss.
Instance Method Summary collapse
-
#initialize(content:, type: 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) ⇒ TypedUri
Returns a new instance of TypedUri.
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
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'lib/relaton_bib/typed_uri.rb', line 9 def content @content end |
#type ⇒ Symbol (readonly)
Returns :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
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_hash ⇒ 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
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 |