Class: Anodator::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/anodator/checker.rb

Instance Method Summary collapse

Constructor Details

#initialize(input_spec, rule_set, default_output_spec, configuration_check = false) ⇒ Checker

Returns a new instance of Checker.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/anodator/checker.rb', line 8

def initialize(input_spec, rule_set, default_output_spec, configuration_check = false)
  @input_spec   = input_spec
  @rule_set     = rule_set
  @output_specs = [default_output_spec]

  unless @input_spec.is_a? InputSpec
    raise ArgumentError.new("input_spec must be InputSpec object")
  end
  unless @rule_set.is_a? RuleSet
    raise ArgumentError.new("rule_set must be RuleSet object")
  end
  unless @output_specs.first.is_a? OutputSpec
    raise ArgumentError.new("default_output_spec must be OutputSpec object")
  end

  Validator::Base.values = @input_spec

  validate_configuration if configuration_check
end

Instance Method Details

#add_output_spec(output_spec, configuration_check = false) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/anodator/checker.rb', line 37

def add_output_spec(output_spec, configuration_check = false)
  unless output_spec.is_a? OutputSpec
    raise ArgumentError.new("output_spec must be OutputSpec object")
  end
  @output_specs << output_spec

  validate_configuration if configuration_check
end

#rule_infoObject



54
55
56
# File 'lib/anodator/checker.rb', line 54

def rule_info
  @rule_set.to_s
end

#run(values) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/anodator/checker.rb', line 46

def run(values)
  @input_spec.source = values
  @rule_set.check_all
  @output_specs.map do |spec|
    spec.generate(@input_spec, @rule_set.results)
  end
end

#validate_configurationObject



28
29
30
31
32
33
34
35
# File 'lib/anodator/checker.rb', line 28

def validate_configuration
  # RuleSet
  @rule_set.validate_configuration
  # OutputSpec
  @output_specs.each do |spec|
    spec.validate_configuration
  end
end