class Quby::Compiler::Entities::Questions::DateQuestion
Constants
- COMPONENT_KEYS
- COMPONENT_PLACEHOLDERS
- DEFAULT_COMPONENTS
- POSSIBLE_COMPONENTS
Attributes
components[RW]
@!attribute [r] components
@return [Array<Symbol>] date parts to show
@!attribute [r] required_components
@return [Array<Symbol>] date parts that are required if the question is required or partly filled out.
optional_components[RW]
@!attribute [r] components
@return [Array<Symbol>] date parts to show
@!attribute [r] required_components
@return [Array<Symbol>] date parts that are required if the question is required or partly filled out.
required_components[RW]
@!attribute [r] components
@return [Array<Symbol>] date parts to show
@!attribute [r] required_components
@return [Array<Symbol>] date parts that are required if the question is required or partly filled out.
Public Class Methods
new(key, options = {})
click to toggle source
Calls superclass method
Quby::Compiler::Entities::Question::new
# File lib/quby/compiler/entities/questions/date_question.rb, line 24 def initialize(key, options = {}) super @components = options[:components] || DEFAULT_COMPONENTS @required_components = options[:required_components] || @components @optional_components = @components - @required_components components.each do |component| component_key = options[:"#{component}_key"] || "#{key}_#{COMPONENT_KEYS[component]}" instance_variable_set("@#{component}_key", component_key.to_sym) end add_date_validation(options[:error_explanation]) end
Public Instance Methods
add_date_validation(explanation)
click to toggle source
# File lib/quby/compiler/entities/questions/date_question.rb, line 39 def add_date_validation(explanation) @validations << {type: :valid_date, subtype: :"valid_date_#{components.sort.join('_')}", explanation: explanation} end
answer_keys()
click to toggle source
# File lib/quby/compiler/entities/questions/date_question.rb, line 49 def answer_keys components.map do |component| send("#{component}_key").to_sym end end
as_json(options = {})
click to toggle source
Calls superclass method
Quby::Compiler::Entities::Question#as_json
# File lib/quby/compiler/entities/questions/date_question.rb, line 62 def as_json(options = {}) component_keys = components.each_with_object({}) do |component, hash| hash["#{component}Key"] = send("#{component}_key") end super.merge(components: components).merge(component_keys) end
claimed_keys()
click to toggle source
# File lib/quby/compiler/entities/questions/date_question.rb, line 45 def claimed_keys [key] + answer_keys end
to_codebook(questionnaire, opts = {})
click to toggle source
# File lib/quby/compiler/entities/questions/date_question.rb, line 69 def to_codebook(questionnaire, opts = {}) output = [] components.each do |component| output << "#{codebook_key(send("#{component}_key"), questionnaire, opts)} " \ "#{type}_#{component} #{codebook_output_range}" output << "\"#{title}\"" unless title.blank? output << options.map(&:to_codebook).join("\n") unless options.blank? output << "" end output.join("\n") end
variable_descriptions()
click to toggle source
# File lib/quby/compiler/entities/questions/date_question.rb, line 55 def variable_descriptions components.each_with_object(key => context_free_title) do |component, hash| key = send("#{component}_key") hash[key] = "#{context_free_title} (#{I18n.t component})" end.with_indifferent_access end