Class: Quby::Compiler::Entities::Text

Inherits:
Item
  • Object
show all
Defined in:
lib/quby/compiler/entities/text.rb

Instance Attribute Summary collapse

Attributes inherited from Item

#presentation, #raw_content, #switch_cycle

Instance Method Summary collapse

Constructor Details

#initialize(str = "", key:, md: nil, **options) ⇒ Text

str is deprecated, use named md instead. str fallback to empty string for quby1 compatibility.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/quby/compiler/entities/text.rb', line 20

def initialize(str="", key:, md: nil, **options)
  if options[:html_content]
    options[:raw_content] = "<div class='item text'>" + options[:html_content] + "</div>"
  end
  super(options)
  @key = key
  @str = md || 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

Instance Attribute Details

#col_spanObject

In case of being displayed inside a table, amount of columns/rows to span



14
15
16
# File 'lib/quby/compiler/entities/text.rb', line 14

def col_span
  @col_span
end

#display_inObject

Returns the value of attribute display_in.



10
11
12
# File 'lib/quby/compiler/entities/text.rb', line 10

def display_in
  @display_in
end

#html_contentObject

Returns the value of attribute html_content.



11
12
13
# File 'lib/quby/compiler/entities/text.rb', line 11

def html_content
  @html_content
end

#keyObject

Returns the value of attribute key.



16
17
18
# File 'lib/quby/compiler/entities/text.rb', line 16

def key
  @key
end

#row_spanObject

Returns the value of attribute row_span.



15
16
17
# File 'lib/quby/compiler/entities/text.rb', line 15

def row_span
  @row_span
end

#strObject (readonly)

Returns the value of attribute str.



9
10
11
# File 'lib/quby/compiler/entities/text.rb', line 9

def str
  @str
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/quby/compiler/entities/text.rb', line 54

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

#as_json(options = {}) ⇒ Object



33
34
35
# File 'lib/quby/compiler/entities/text.rb', line 33

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

#htmlObject



37
38
39
# File 'lib/quby/compiler/entities/text.rb', line 37

def html
  @html_content || text
end

#textObject



41
42
43
44
# File 'lib/quby/compiler/entities/text.rb', line 41

def text
  return "" if str.blank?
  @text ||= Quby::Compiler::MarkdownParser.new(str).to_html
end

#to_sObject



65
66
67
# File 'lib/quby/compiler/entities/text.rb', line 65

def to_s
  text
end

#typeObject



46
47
48
# File 'lib/quby/compiler/entities/text.rb', line 46

def type
  "text"
end

#validate_answer(answer_hash) ⇒ Object



50
51
52
# File 'lib/quby/compiler/entities/text.rb', line 50

def validate_answer(answer_hash)
  true
end