Class: Hecks::Bluebook::DSL::TranslationBuilder

Inherits:
Object
  • Object
show all
Includes:
WordGate
Defined in:
lib/hecks/bluebook/dsl/translation_builder.rb

Constant Summary collapse

GRAMMAR_CONTEXT =
"Translation"

Constants included from WordGate

WordGate::NOT_ADMITTED

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, from:, to:) ⇒ TranslationBuilder

Returns a new instance of TranslationBuilder.

Raises:



191
192
193
194
195
196
197
198
199
200
201
# File 'lib/hecks/bluebook/dsl/translation_builder.rb', line 191

def initialize(domain, from:, to:)
  raise Malformed, "a translation names no domain" if domain.to_s.empty?
  raise Malformed, "#{domain}'s translation says nothing about its origin era (from:)" if from.to_s.empty?
  raise Malformed, "#{domain}'s translation says nothing about its destination era (to:)" if to.to_s.empty?

  @domain     = domain
  @from       = from
  @to         = to
  @aggregates = []
  @retired    = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hecks::Bluebook::DSL::WordGate

Class Method Details

.build(domain, from:, to:, &block) ⇒ Object



235
236
237
238
239
# File 'lib/hecks/bluebook/dsl/translation_builder.rb', line 235

def self.build(domain, from:, to:, &block)
  builder = new(domain, from: from, to: to)
  builder.instance_eval(&block) if block
  builder.build
end

Instance Method Details

#aggregate_impl(name, was: nil, &block) ⇒ Object

RENAMED FROM aggregate — item #13's full metaprogrammed dispatch (slice 4c). Not bootstrap-reachable — this "Translation" -context aggregate (opens a TranslationAggregateBuilder) is a different (context, word) pair than "Bluebook"-context aggregate (the one translation.bluebook itself is described with), so it's never used to describe the language's own translation chapter.



210
211
212
213
214
# File 'lib/hecks/bluebook/dsl/translation_builder.rb', line 210

def aggregate_impl(name, was: nil, &block)
  builder = TranslationAggregateBuilder.new(name, was: was)
  builder.instance_eval(&block) if block
  @aggregates << builder.build
end

#buildObject

method_missing/respond_to_missing? — same removal as TranslationAggregateBuilder's own, one level up: WordGate (included above) answers off the self-hosted grammar table now instead of a hand-typed "it declares aggregate blocks and retired aggregates" message.



229
230
231
232
233
# File 'lib/hecks/bluebook/dsl/translation_builder.rb', line 229

def build
  MetaValidator.call_translation(
    Translation.new(domain: @domain, from: @from, to: @to, aggregates: @aggregates, retired: @retired)
  )
end