Sha256: 8439383ac58e7824131d57c26956073f8ae9f909fb54647f24ff60c4112985f7
Contents?: true
Size: 937 Bytes
Versions: 3
Compression:
Stored size: 937 Bytes
Contents
# frozen_string_literal: true require "redcarpet" module Uptriever class Document attr_reader :id, :path, :link, :tags, :groups, :weight def initialize(id, path, link, tags: nil, groups: nil, weight: 1.0) @id = id @path = path @link = link @tags = tags @groups = groups @weight = weight end def to_html case File.extname(path) when ".md" markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true) markdown.render(File.read(path)) when ".html" File.read(path) else raise ArgumentError, "Unsupported file type: #{path}" end end def to_chunk_json { chunk_html: to_html, link:, tracking_id: id, weight: }.tap do _1.merge!(tag_set: tags) if tags _1.merge!(group_tracking_ids: groups) if groups end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
uptriever-0.1.1 | lib/uptriever/document.rb |
uptriever-0.1.0 | lib/uptriever/document.rb |
uptriever-0.0.1 | lib/uptriever/document.rb |