Class: JCR::Context

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruleset = nil, trace = false) ⇒ Context

Returns a new instance of Context.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jcr/jcr.rb', line 64

def initialize( ruleset = nil, trace = false )
  @trace = trace
  @failed_roots = []
  if ruleset
    ingested = JCR.ingest_ruleset( ruleset, nil, nil )
    @mapping = ingested.mapping
    @callbacks = ingested.callbacks
    @id = ingested.id
    @tree = ingested.tree
    @roots = ingested.roots
  end
  @failure_report_line_length = 80
end

Instance Attribute Details

#callbacksObject

Returns the value of attribute callbacks.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def callbacks
  @callbacks
end

#catalogObject

Returns the value of attribute catalog.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def catalog
  @catalog
end

#failed_rootsObject

Returns the value of attribute failed_roots.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def failed_roots
  @failed_roots
end

#failure_reportObject

Returns the value of attribute failure_report.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def failure_report
  @failure_report
end

#failure_report_line_lengthObject

Returns the value of attribute failure_report_line_length.



34
35
36
# File 'lib/jcr/jcr.rb', line 34

def failure_report_line_length
  @failure_report_line_length
end

#idObject

Returns the value of attribute id.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def id
  @id
end

#mappingObject

Returns the value of attribute mapping.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def mapping
  @mapping
end

#rootsObject

Returns the value of attribute roots.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def roots
  @roots
end

#traceObject

Returns the value of attribute trace.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def trace
  @trace
end

#treeObject

Returns the value of attribute tree.



33
34
35
# File 'lib/jcr/jcr.rb', line 33

def tree
  @tree
end

Instance Method Details

#add_ruleset_alias(ruleset_alias, alias_uri) ⇒ Object



36
37
38
39
40
41
# File 'lib/jcr/jcr.rb', line 36

def add_ruleset_alias( ruleset_alias, alias_uri )
  unless @catalog
    @catalog = Hash.new
  end
  @catalog[ ruleset_alias ] = alias_uri
end

#evaluate(data, root_name = nil) ⇒ Object



60
61
62
# File 'lib/jcr/jcr.rb', line 60

def evaluate( data, root_name = nil )
  JCR.evaluate_ruleset( data, self, root_name )
end

#map_ruleset_alias(ruleset_alias, alias_uri) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/jcr/jcr.rb', line 49

def map_ruleset_alias( ruleset_alias, alias_uri )
  if @catalog
    a = @catalog[ ruleset_alias ]
    if a
      return a
    end
  end
  #else
  return alias_uri
end

#override(ruleset) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/jcr/jcr.rb', line 78

def override( ruleset )
  overridden = JCR.ingest_ruleset( ruleset, @mapping, nil )
  mapping = {}
  mapping.merge!( @mapping )
  mapping.merge!( overridden.mapping )
  overridden.mapping=mapping
  callbacks = {}
  callbacks.merge!( @callbacks )
  callbacks.merge!( overridden.callbacks )
  overridden.callbacks = callbacks
  overridden.roots.concat( @roots )
  return overridden
end

#override!(ruleset) ⇒ Object



92
93
94
95
96
97
# File 'lib/jcr/jcr.rb', line 92

def override!( ruleset )
  overridden = JCR.ingest_ruleset( ruleset, @mapping, nil )
  @mapping.merge!( overridden.mapping )
  @callbacks.merge!( overridden.callbacks )
  @roots.concat( overridden.roots )
end

#remove_ruleset_alias(ruleset_alias) ⇒ Object



43
44
45
46
47
# File 'lib/jcr/jcr.rb', line 43

def remove_ruleset_alias( ruleset_alias )
  if @catalog
    @catalog.delete( ruleset_alias )
  end
end