Class: ElectricProfile::Question
- Inherits:
-
Object
- Object
- ElectricProfile::Question
- Defined in:
- lib/electric_profile_ruby/question.rb
Constant Summary collapse
- TYPES =
['multi_choice', 'number', 'short_text', 'long_text']
Instance Attribute Summary collapse
-
#allowMultiple ⇒ Object
Returns the value of attribute allowMultiple.
-
#answerOptionOrder ⇒ Object
Returns the value of attribute answerOptionOrder.
-
#answerOptions ⇒ Object
Returns the value of attribute answerOptions.
-
#baseLogic ⇒ Object
Returns the value of attribute baseLogic.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#customerId ⇒ Object
Returns the value of attribute customerId.
-
#derivationLogic ⇒ Object
Returns the value of attribute derivationLogic.
-
#derived ⇒ Object
Returns the value of attribute derived.
-
#error ⇒ Object
Returns the value of attribute error.
-
#exclusiveAnswerOptions ⇒ Object
Returns the value of attribute exclusiveAnswerOptions.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
-
#regExValidation ⇒ Object
Returns the value of attribute regExValidation.
-
#regExValidationMessage ⇒ Object
Returns the value of attribute regExValidationMessage.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .all ⇒ Object
- .all_with_category(category) ⇒ Object
- .all_without_category(category) ⇒ Object
- .find(id) ⇒ Object
Instance Method Summary collapse
-
#initialize(atts) ⇒ Question
constructor
A new instance of Question.
- #initialize_client ⇒ Object
- #save ⇒ Object
- #save_existing ⇒ Object
- #save_new ⇒ Object
Constructor Details
#initialize(atts) ⇒ Question
Returns a new instance of Question.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/electric_profile_ruby/question.rb', line 7 def initialize(atts) atts = atts.inject({}){ |memo, (k, v) | memo[k.to_sym] = v; memo } @id = atts[:id] @customerId = atts[:customerId] @name = atts[:name] @prompt = atts[:prompt] @type = atts[:type] @answerOptions = atts[:answerOptions] || {} @allowMultiple = atts[:allowMultiple] || false @categories = atts[:categories] || [] @exclusiveAnswerOptions = atts[:exclusiveAnswerOptions] @answerOptionOrder = atts[:answerOptionOrder] @regExValidation = atts[:regExValidation] @regExValidationMessage = atts[:regExValidationMessage] || {} @baseLogic = atts[:baseLogic] @derived = atts[:derived] || false @derivationLogic = atts[:derivationLogic] || [] end |
Instance Attribute Details
#allowMultiple ⇒ Object
Returns the value of attribute allowMultiple.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def allowMultiple @allowMultiple end |
#answerOptionOrder ⇒ Object
Returns the value of attribute answerOptionOrder.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def answerOptionOrder @answerOptionOrder end |
#answerOptions ⇒ Object
Returns the value of attribute answerOptions.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def answerOptions @answerOptions end |
#baseLogic ⇒ Object
Returns the value of attribute baseLogic.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def baseLogic @baseLogic end |
#categories ⇒ Object
Returns the value of attribute categories.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def categories @categories end |
#customerId ⇒ Object
Returns the value of attribute customerId.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def customerId @customerId end |
#derivationLogic ⇒ Object
Returns the value of attribute derivationLogic.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def derivationLogic @derivationLogic end |
#derived ⇒ Object
Returns the value of attribute derived.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def derived @derived end |
#error ⇒ Object
Returns the value of attribute error.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def error @error end |
#exclusiveAnswerOptions ⇒ Object
Returns the value of attribute exclusiveAnswerOptions.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def exclusiveAnswerOptions @exclusiveAnswerOptions end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def name @name end |
#prompt ⇒ Object
Returns the value of attribute prompt.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def prompt @prompt end |
#regExValidation ⇒ Object
Returns the value of attribute regExValidation.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def regExValidation @regExValidation end |
#regExValidationMessage ⇒ Object
Returns the value of attribute regExValidationMessage.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def regExValidationMessage @regExValidationMessage end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/electric_profile_ruby/question.rb', line 4 def type @type end |
Class Method Details
.all ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/electric_profile_ruby/question.rb', line 97 def self.all client = Client.new if client.fetch_questions client.data["Items"].map { |atts| new atts } else raise StandardError, client.error end end |
.all_with_category(category) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/electric_profile_ruby/question.rb', line 106 def self.all_with_category(category) client = Client.new if client.fetch_questions(categoryIncluded: category) client.data["Items"].map { |atts| new atts } else raise StandardError, client.error end end |
.all_without_category(category) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/electric_profile_ruby/question.rb', line 115 def self.all_without_category(category) client = Client.new if client.fetch_questions(categoryExcluded: category) client.data["Items"].map { |atts| new atts } else raise StandardError, client.error end end |
.find(id) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/electric_profile_ruby/question.rb', line 88 def self.find(id) client = Client.new if client.fetch_question(id) new client.data else raise StandardError, client.error end end |
Instance Method Details
#initialize_client ⇒ Object
124 125 126 |
# File 'lib/electric_profile_ruby/question.rb', line 124 def initialize_client @client ||= Client.new end |
#save ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/electric_profile_ruby/question.rb', line 26 def save if @id save_existing else save_new end end |
#save_existing ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/electric_profile_ruby/question.rb', line 61 def save_existing initialize_client attributes = { id: @id, customerId: @customerId, name: @name, prompt: @prompt, type: @type, answerOptions: @answerOptions, allowMultiple: @allowMultiple, categories: @categories, exclusiveAnswerOptions: @exclusiveAnswerOptions, answerOptionOrder: @answerOptionOrder, regExValidation: @regExValidation, regExValidationMessage: @regExValidationMessage, baseLogic: @baseLogic, derived: @derived, derivationLogic: @derivationLogic } if @client.update_question(attributes) true else @error = @client.error false end end |
#save_new ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/electric_profile_ruby/question.rb', line 34 def save_new initialize_client attributes = { name: @name, prompt: @prompt, type: @type, answerOptions: @answerOptions, allowMultiple: @allowMultiple, categories: @categories, exclusiveAnswerOptions: @exclusiveAnswerOptions, answerOptionOrder: @answerOptionOrder, regExValidation: @regExValidation, regExValidationMessage: @regExValidationMessage, baseLogic: @baseLogic, derived: @derived, derivationLogic: @derivationLogic } if @client.create_question(attributes) @id = @client.data["id"] @customerId = @client.data["customerId"] true else @error = @client.error false end end |