Class: Relaxo::QueryServer::Mapper

Inherits:
Loader
  • Object
show all
Defined in:
lib/relaxo/query_server/mapper.rb

Constant Summary

Constants inherited from Loader

Loader::DEFAULT

Instance Method Summary collapse

Methods inherited from Loader

#add_libraries, #load, #load_default

Constructor Details

#initialize(context) ⇒ Mapper

Returns a new instance of Mapper.



57
58
59
60
61
62
# File 'lib/relaxo/query_server/mapper.rb', line 57

def initialize(context)
  super()
  
  @context = context
  @functions = []
end

Instance Method Details

#add_function(text) ⇒ Object

Adds a function by parsing the text, typically containing a textual representation of a lambda.



65
66
67
# File 'lib/relaxo/query_server/mapper.rb', line 65

def add_function(text)
  @functions << @context.parse_function(text, binding)
end

#map(document) ⇒ Object

Map a document to a set of results by appling all functions.



70
71
72
73
74
75
76
77
# File 'lib/relaxo/query_server/mapper.rb', line 70

def map(document)
  # Force load the default library:
  load_default
  
  @functions.map do |function|
    MappingProcess.new(@context, @libraries, function).run(document)
  end
end