Class: Yaoc::ConverterBuilder

Inherits:
Object
  • Object
show all
Includes:
BuilderDSLMethods
Defined in:
lib/yaoc/converter_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BuilderDSLMethods

#add_mapping, #build_commands_ordered, #fetch_with, #rule, #with_strategy

Constructor Details

#initialize(command_order = :recorded_order, fetcher = :fetch) ⇒ ConverterBuilder

Returns a new instance of ConverterBuilder.



95
96
97
98
99
100
101
# File 'lib/yaoc/converter_builder.rb', line 95

def initialize(command_order=:recorded_order, fetcher=:fetch)
  self.build_commands = []
  self.command_order = command_order
  self.fetcher = fetcher
  self.strategy = :to_hash_mapping
  self.all_commands_applied = false
end

Instance Attribute Details

#all_commands_appliedObject

Returns the value of attribute all_commands_applied.



92
93
94
# File 'lib/yaoc/converter_builder.rb', line 92

def all_commands_applied
  @all_commands_applied
end

#build_commandsObject

Returns the value of attribute build_commands.



92
93
94
# File 'lib/yaoc/converter_builder.rb', line 92

def build_commands
  @build_commands
end

#command_orderObject

Returns the value of attribute command_order.



92
93
94
# File 'lib/yaoc/converter_builder.rb', line 92

def command_order
  @command_order
end

#strategyObject

Returns the value of attribute strategy.



92
93
94
# File 'lib/yaoc/converter_builder.rb', line 92

def strategy
  @strategy
end

Instance Method Details

#apply_commands!Object



103
104
105
106
107
108
# File 'lib/yaoc/converter_builder.rb', line 103

def apply_commands!
  reset_converters!
  self.all_commands_applied = true

  build_commands_ordered.each &:call
end

#converter(fetch_able, target_source = nil) ⇒ Object



110
111
112
113
# File 'lib/yaoc/converter_builder.rb', line 110

def converter(fetch_able, target_source=nil)
  raise "BuildCommandsNotExecuted" unless self.all_commands_applied?
  converter_class.new(fetch_able, fetcher, target_source || ->(attrs){ attrs})
end

#fetcher=(new_fetcher) ⇒ Object



115
116
117
# File 'lib/yaoc/converter_builder.rb', line 115

def fetcher=(new_fetcher)
  @fetcher= new_fetcher
end