Sha256: 6e3ae53e3af69f7eb2b360147ad41a9695c03c484034eb9ccdc92ce9a57c1cdd

Contents?: true

Size: 876 Bytes

Versions: 1

Compression:

Stored size: 876 Bytes

Contents

module RailsConnector

class TextLink

  def initialize(link_data)
    @data = link_data
  end

  def query_and_fragment
    query = @data["query"]
    fragment = @data["fragment"]

    str = ''
    str << "?#{query}" if query.present?
    str << "##{fragment}" if fragment.present?
    str
  end

  def internal?
    !url
  end

  def external_url
    url =~ /(external:)?(.*)/
    $2
  end

  def obj_id
    @data["destination"]
  end

  def html_attribute_snippet
    tag_name = @data["tag_name"]
    title = @data["title"]
    target = @data["target"]

    parts = []
    parts << %{alt="#{title}"} if tag_name == 'img' || tag_name == 'input'
    parts << %{title="#{title}"} if (tag_name == 'a' || tag_name == 'link') && title.present?
    parts << %{target="#{target}"} if target.present?
    parts.join(' ')
  end

  private

  def url
    @data["url"]
  end

end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
infopark_cloud_connector-7.1.0 lib/rails_connector/text_link.rb