Sha256: 9e739c085fb480819dad7bc631150ec3b32a97cec8c135f82b5448aae5ce8276

Contents?: true

Size: 960 Bytes

Versions: 94

Compression:

Stored size: 960 Bytes

Contents

module Search
  class Article
    delegate :config, :title, :description, :body, :path, :doc_type, to: :@doc

    def initialize(doc, html)
      @doc  = doc
      @html = html
    end

    def relative_path
      @relative_path ||= "#{config[:base_url_path]}/#{path.relative_path_from(config[:origin])}".gsub('.md', '')
    end

    def product
      @product ||= begin
        product = relative_path.split('/')[1]
        if product == 'messaging'
          "#{relative_path.split('/')[1]} > #{relative_path.split('/')[2]}"
        else
          product
        end
      end
    end

    def to_h
      {
        title: title,
        heading: @html.css('body').children[0].text.strip,
        anchor: @html.css('body').children[0].text.parameterize,
        description: description,
        document_class: doc_type,
        path: relative_path,
        document_path: path,
        body: @html.text,
        product: product,
      }
    end
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.0.131 lib/nexmo_developer/app/services/search/article.rb
station-0.0.130 lib/nexmo_developer/app/services/search/article.rb
station-0.0.129 lib/nexmo_developer/app/services/search/article.rb
station-0.0.128 lib/nexmo_developer/app/services/search/article.rb
station-0.0.127 lib/nexmo_developer/app/services/search/article.rb
station-0.0.126 lib/nexmo_developer/app/services/search/article.rb
station-0.0.125 lib/nexmo_developer/app/services/search/article.rb
station-0.0.124 lib/nexmo_developer/app/services/search/article.rb
station-0.0.123 lib/nexmo_developer/app/services/search/article.rb
station-0.0.122 lib/nexmo_developer/app/services/search/article.rb
station-0.0.121 lib/nexmo_developer/app/services/search/article.rb
station-0.0.120 lib/nexmo_developer/app/services/search/article.rb
station-0.0.119 lib/nexmo_developer/app/services/search/article.rb
station-0.0.118 lib/nexmo_developer/app/services/search/article.rb
station-0.0.115 lib/nexmo_developer/app/services/search/article.rb
station-0.0.114 lib/nexmo_developer/app/services/search/article.rb
station-0.0.113 lib/nexmo_developer/app/services/search/article.rb
station-0.0.112 lib/nexmo_developer/app/services/search/article.rb
station-0.0.111 lib/nexmo_developer/app/services/search/article.rb
station-0.0.110 lib/nexmo_developer/app/services/search/article.rb