Sha256: 0227d378594176573f815754f2d31a956d5b208cbe7de14d11294321f131d815

Contents?: true

Size: 1.49 KB

Versions: 9

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require 'quby/compiler/entities/item'

module Quby
  module Compiler
    module Entities
      class Text < Item
        attr_reader :str
        attr_accessor :display_in
        attr_accessor :html_content

        # In case of being displayed inside a table, amount of columns/rows to span
        attr_accessor :col_span
        attr_accessor :row_span

        def initialize(str, options = {})
          if options[:html_content]
            options[:raw_content] = "<div class='item text'>" + options[:html_content] + "</div>"
          end
          super(options)
          @str = str
          @html_content = options[:html_content]
          @display_in = options[:display_in] || [:paged]
          @col_span = options[:col_span] || 1
          @row_span = options[:row_span] || 1
        end

        def as_json(options = {})
          super().merge(text: text)
        end

        def html
          @html_content || text
        end

        def text
          @text ||= Quby::Compiler::MarkdownParser.new(str).to_html
        end

        def key
          't0'
        end

        def type
          "text"
        end

        def validate_answer(answer_hash)
          true
        end

        def ==(other)
          case other.class
          when String
            text == other
          when self.class
            text == other.text
          else
            false
          end
        end

        def to_s
          text
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
quby-compiler-0.5.9 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.8 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.7 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.6 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.5 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.4 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.3 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.2 lib/quby/compiler/entities/text.rb
quby-compiler-0.5.1 lib/quby/compiler/entities/text.rb