Class: Macros4Cuke::FormattingService
- Inherits:
-
Object
- Object
- Macros4Cuke::FormattingService
- Defined in:
- lib/macros4cuke/formatting-service.rb
Overview
A worker class that drives the rendering of macro-steps in any registered format.
Instance Attribute Summary collapse
-
#formatters ⇒ Object
readonly
The list of registered formatters.
-
#walker_factory ⇒ Object
readonly
Link to a factory of walker objects that visit macro collections.
Instance Method Summary collapse
-
#initialize ⇒ FormattingService
constructor
Constructor.
-
#register(aFormatter) ⇒ Object
Register a formatter.
-
#start!(aMacroCollection) ⇒ Object
Launch the rendering(s) of the given macro collection.
Constructor Details
#initialize ⇒ FormattingService
Constructor.
22 23 24 25 |
# File 'lib/macros4cuke/formatting-service.rb', line 22 def initialize() @formatters = [] @walker_factory = CollWalkerFactory.new end |
Instance Attribute Details
#formatters ⇒ Object (readonly)
The list of registered formatters
15 16 17 |
# File 'lib/macros4cuke/formatting-service.rb', line 15 def formatters @formatters end |
#walker_factory ⇒ Object (readonly)
Link to a factory of walker objects that visit macro collections
18 19 20 |
# File 'lib/macros4cuke/formatting-service.rb', line 18 def walker_factory @walker_factory end |
Instance Method Details
#register(aFormatter) ⇒ Object
Register a formatter. Raises an exception when the formatter implements an unknown formatting event.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/macros4cuke/formatting-service.rb', line 31 def register(aFormatter) # Get the list of formatted events supported by the formatter supported_events = aFormatter.implements # Complain if list is empty or nil if supported_events.nil? || supported_events.empty? fail(NoFormattingEventForFormatter.new(aFormatter)) end # Check that each event from the event list the formatter is known. supported_events.each do |event| unless Formatter::AllNotifications.include? event fail(UnknownFormattingEvent.new(aFormatter, event)) end end formatters << aFormatter end |
#start!(aMacroCollection) ⇒ Object
Launch the rendering(s) of the given macro collection.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/macros4cuke/formatting-service.rb', line 51 def start!(aMacroCollection) # Create a walker (that will visit the collection) walker = walker_factory.build_walker(aMacroCollection) walker.each do |visit_event| (msg, nesting_level) = visit_event[0..1] # Notify each formatter of the visit event. formatters.each do |fmt| accepted_notifications = fmt.implements if accepted_notifications.include? msg # Assumption: all nil argument(s) are at the end arg_vector = visit_event[2..-1].reject { |an_arg| an_arg.nil? } fmt.send(msg, nesting_level, *arg_vector) end end end end |