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, options = {}) ⇒ Text

Returns a new instance of Text.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/quby/compiler/entities/text.rb', line 17

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

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

#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



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

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

#as_json(options = {}) ⇒ Object



29
30
31
# File 'lib/quby/compiler/entities/text.rb', line 29

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

#htmlObject



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

def html
  @html_content || text
end

#keyObject



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

def key
  't0'
end

#textObject



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

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

#to_sObject



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

def to_s
  text
end

#typeObject



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

def type
  "text"
end

#validate_answer(answer_hash) ⇒ Object



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

def validate_answer(answer_hash)
  true
end