Class: Quby::Questionnaires::Entities::Validation
- Inherits:
-
Object
- Object
- Quby::Questionnaires::Entities::Validation
- Defined in:
- lib/quby/questionnaires/entities/validation.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(config) ⇒ Validation
constructor
A new instance of Validation.
- #type ⇒ Object
Constructor Details
#initialize(config) ⇒ Validation
Returns a new instance of Validation.
7 8 9 |
# File 'lib/quby/questionnaires/entities/validation.rb', line 7 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/quby/questionnaires/entities/validation.rb', line 5 def config @config end |
Instance Method Details
#as_json ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/quby/questionnaires/entities/validation.rb', line 15 def as_json case type when :regexp valc = config.clone valc[:matcher] = valc[:matcher].source.to_s # Replace single backslashes with two backslashes valc[:matcher].gsub!("\\", "\\\\") valc else config end.deep_transform_keys{ |key| key.to_s.camelize(:lower) } end |
#type ⇒ Object
11 12 13 |
# File 'lib/quby/questionnaires/entities/validation.rb', line 11 def type config[:type] end |