Class: Quby::Questionnaires::Entities::Validation

Inherits:
Object
  • Object
show all
Defined in:
lib/quby/questionnaires/entities/validation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (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_jsonObject



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

#typeObject



11
12
13
# File 'lib/quby/questionnaires/entities/validation.rb', line 11

def type
  config[:type]
end