Class: Question
- Inherits:
-
Object
- Object
- Question
- Defined in:
- lib/models/question.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#answer ⇒ Object
returns an existing one or nil if there is no.
-
#answer! ⇒ Object
creates a new answer or returns an existing one.
- #has_answer? ⇒ Boolean
-
#initialize(node, repository) ⇒ Question
constructor
A new instance of Question.
- #reply_type ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(node, repository) ⇒ Question
Returns a new instance of Question.
4 5 6 |
# File 'lib/models/question.rb', line 4 def initialize(node, repository) @query = NodeQuery.new(node, repository) end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
2 3 4 |
# File 'lib/models/question.rb', line 2 def query @query end |
Instance Method Details
#answer ⇒ Object
returns an existing one or nil if there is no
21 22 23 24 25 26 |
# File 'lib/models/question.rb', line 21 def answer node = query.value(QV.has_answer) return nil if node.nil? Answer.create(reply_type, node, query.repository) end |
#answer! ⇒ Object
creates a new answer or returns an existing one
29 30 31 |
# File 'lib/models/question.rb', line 29 def answer! answer || create_answer end |
#has_answer? ⇒ Boolean
16 17 18 |
# File 'lib/models/question.rb', line 16 def has_answer? query.value_exists?(QV.has_answer) end |
#reply_type ⇒ Object
12 13 14 |
# File 'lib/models/question.rb', line 12 def reply_type QuestionReplyType.to_sym(query) end |
#text ⇒ Object
8 9 10 |
# File 'lib/models/question.rb', line 8 def text query.value(QV.text).to_s end |