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, #noop, #rule, #with_strategy

Constructor Details

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

Returns a new instance of ConverterBuilder.



98
99
100
101
102
103
104
# File 'lib/yaoc/converter_builder.rb', line 98

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.



95
96
97
# File 'lib/yaoc/converter_builder.rb', line 95

def all_commands_applied
  @all_commands_applied
end

#build_commandsObject

Returns the value of attribute build_commands.



95
96
97
# File 'lib/yaoc/converter_builder.rb', line 95

def build_commands
  @build_commands
end

#command_orderObject

Returns the value of attribute command_order.



95
96
97
# File 'lib/yaoc/converter_builder.rb', line 95

def command_order
  @command_order
end

#strategyObject

Returns the value of attribute strategy.



95
96
97
# File 'lib/yaoc/converter_builder.rb', line 95

def strategy
  @strategy
end

Instance Method Details

#apply_commands!Object



106
107
108
109
110
111
# File 'lib/yaoc/converter_builder.rb', line 106

def apply_commands!
  reset_converters!
  self.all_commands_applied = true

  build_commands_ordered.each &:call
end

#converter(fetch_able, target_source = nil) ⇒ Object



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

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



118
119
120
# File 'lib/yaoc/converter_builder.rb', line 118

def fetcher=(new_fetcher)
  @fetcher= new_fetcher
end