Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 32 additions and 10 deletions.
  1. +12 −1 app/models/question.rb
  2. +18 −0 app/models/session.rb
  3. +1 −8 app/storage/question_repository.rb
  4. +1 −1 app/storage/session_repository.rb
View
13 app/models/question.rb
@@ -3,12 +3,23 @@ module Models
class Question
attr_accessor :id, :text
+ def self.from_hash(question_hash)
+ Question.new.tap do |question|
+ question.id = question_hash['_id'].to_s
+ question.text = question_hash['text']
+ end
+ end
+
def to_hash
{
- :id => id,
+ :_id => id,
:text => text
}
end
+
+ def answered?
+ false
+ end
end
end
end
View
18 app/models/session.rb
@@ -3,6 +3,24 @@ module Models
class Session
attr_accessor :user_first_name, :user_last_name, :questions
+ def initialize
+ @questions = []
+ end
+
+ def self.from_hash(session_hash)
+ session = Session.new
+ session.user_first_name = session_hash['user_first_name']
+ session.user_last_name = session_hash['user_last_name']
+
+ session_hash['questions'].each do |question_hash|
+ session.questions << Question.from_hash(question_hash)
+ end
+
+ puts session.inspect
+ session
+ end
+
+
def to_hash
hash = {
:user_first_name => user_first_name,
View
9 app/storage/question_repository.rb
@@ -4,14 +4,7 @@ class QuestionRepository
include StorageHelper
def get_all_questions
- [].tap do |questions|
- collection.find.each do |question_hash|
- question = HireMe::Models::Question.new
- question.id = question_hash['_id'].to_s
- question.text = question_hash['text']
- questions << question
- end
- end
+ collection.find.collect { |q| HireMe::Models::Question.from_hash(q) }
end
private
View
2 app/storage/session_repository.rb
@@ -17,7 +17,7 @@ def create_session(user, question_list)
end
def get_session(id)
- session_hash = collection.find(id)
+ session_hash = collection.find_one(BSON::ObjectId.from_string(id)).to_hash
HireMe::Models::Session.from_hash(session_hash)
end

No commit comments for this range

Something went wrong with that request. Please try again.