Class: Quby::Questionnaires::Entities::Questions::DateQuestion
- Inherits:
-
Quby::Questionnaires::Entities::Question
- Object
- Item
- Quby::Questionnaires::Entities::Question
- Quby::Questionnaires::Entities::Questions::DateQuestion
- Defined in:
- lib/quby/questionnaires/entities/questions/date_question.rb
Constant Summary collapse
- POSSIBLE_COMPONENTS =
%i( day month year hour minute )
- COMPONENT_KEYS =
Hash[POSSIBLE_COMPONENTS.zip %w( dd mm yyyy hh ii)]
- COMPONENT_PLACEHOLDERS =
Hash[POSSIBLE_COMPONENTS.zip %w( DD MM YYYY hh mm)]
- DEFAULT_COMPONENTS =
%i( day month year )
Constants inherited from Quby::Questionnaires::Entities::Question
Quby::Questionnaires::Entities::Question::MARKDOWN_ATTRIBUTES
Instance Attribute Summary collapse
-
#components ⇒ Array<Symbol>
Date parts to show.
-
#optional_components ⇒ Object
Returns the value of attribute optional_components.
-
#required_components ⇒ Array<Symbol>
Date parts that are required if the question is required or partly filled out.
Attributes inherited from Quby::Questionnaires::Entities::Question
#allow_blank_titles, #allow_duplicate_option_values, #as, #autocomplete, #col_span, #cols, #context_free_title, #default_invisible, #default_position, #dependencies, #depends_on, #description, #deselectable, #disallow_bulk, #display_modes, #extra_data, #group_maximum_answered, #group_minimum_answered, #hidden, #input_data, #key, #labels, #lines, #options, #parent, #parent_option_key, #question_group, #questionnaire, #row_span, #sbg_key, #score_header, #sets_textvar, #show_values, #size, #table, #title, #type, #unit, #validations
Attributes inherited from Item
#presentation, #raw_content, #switch_cycle
Instance Method Summary collapse
- #answer_keys ⇒ Object
- #as_json(options = {}) ⇒ Object
- #claimed_keys ⇒ Object
-
#initialize(key, options = {}) ⇒ DateQuestion
constructor
A new instance of DateQuestion.
- #to_codebook(questionnaire, opts = {}) ⇒ Object
- #variable_descriptions ⇒ Object
Methods inherited from Quby::Questionnaires::Entities::Question
#codebook_key, #codebook_output_range, #codebook_output_type, #hidden?, #html_id, #input_keys, #key_in_use?, #maximum, #minimum, #set_depends_on, #show_values_in_mode?, #subquestion?, #subquestions, #view_selector
Constructor Details
#initialize(key, options = {}) ⇒ DateQuestion
Returns a new instance of DateQuestion.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 24 def initialize(key, = {}) super @components = [:components] || DEFAULT_COMPONENTS @required_components = [:required_components] || @components @optional_components = @components - @required_components components.each do |component| component_key = [:"#{component}_key"] || "#{key}_#{COMPONENT_KEYS[component]}" instance_variable_set("@#{component}_key", component_key.to_sym) end end |
Instance Attribute Details
#components ⇒ Array<Symbol>
Returns date parts to show.
22 23 24 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 22 def components @components end |
#optional_components ⇒ Object
Returns the value of attribute optional_components.
22 23 24 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 22 def optional_components @optional_components end |
#required_components ⇒ Array<Symbol>
Returns date parts that are required if the question is required or partly filled out.
22 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 22 attr_accessor :components, :required_components, :optional_components |
Instance Method Details
#answer_keys ⇒ Object
41 42 43 44 45 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 41 def answer_keys components.map do |component| send("#{component}_key").to_sym end end |
#as_json(options = {}) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 54 def as_json( = {}) 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 ⇒ Object
37 38 39 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 37 def claimed_keys [key] + answer_keys end |
#to_codebook(questionnaire, opts = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 61 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 << .map(&:to_codebook).join("\n") unless .blank? output << "" end output.join("\n") end |
#variable_descriptions ⇒ Object
47 48 49 50 51 52 |
# File 'lib/quby/questionnaires/entities/questions/date_question.rb', line 47 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 |