Sha256: 7522988f516fbd5929951f14463da2491950f478284ce1e668195d334bcab4b3

Contents?: true

Size: 1.12 KB

Versions: 39

Compression:

Stored size: 1.12 KB

Contents

require "addressable"

module RelatonBib
  # Typed URI
  class TypedUri
    # @return [Symbol] :src/:obp/:rss
    attr_reader :type
    # @retutn [Addressable::URI]
    attr_reader :content

    # @param type [String, NilClass] src/obp/rss
    # @param content [String]
    def initialize(content:, type: nil)
      @type    = type
      @content = Addressable::URI.parse content if content
    end

    # @param url [String]
    def content=(url)
      @content = Addressable::URI.parse url
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder)
      doc = builder.uri content.to_s
      doc[:type] = type if type
    end

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

    # @param prefix [String]
    # @param count [Integer] number of links
    # @return [String]
    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
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
relaton-bib-1.11.4 lib/relaton_bib/typed_uri.rb
relaton-bib-1.11.3 lib/relaton_bib/typed_uri.rb
relaton-bib-1.11.2 lib/relaton_bib/typed_uri.rb
relaton-bib-1.11.1 lib/relaton_bib/typed_uri.rb
relaton-bib-1.11.0 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.7 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.6 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.5 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.4 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.3 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.2 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.1 lib/relaton_bib/typed_uri.rb
relaton-bib-1.10.0 lib/relaton_bib/typed_uri.rb
relaton-bib-1.9.23 lib/relaton_bib/typed_uri.rb
relaton-bib-1.9.22 lib/relaton_bib/typed_uri.rb
relaton-bib-1.9.21 lib/relaton_bib/typed_uri.rb
relaton-bib-1.9.20 lib/relaton_bib/typed_uri.rb
relaton-bib-1.9.19 lib/relaton_bib/typed_uri.rb
relaton-bib-1.9.18 lib/relaton_bib/typed_uri.rb