Sha256: 7e117e0497911334121563998d12521800abb291591a61993a39ec7ed3f88bc6

Contents?: true

Size: 542 Bytes

Versions: 3

Compression:

Stored size: 542 Bytes

Contents

# frozen_string_literal: true

module Umwelt::Node
  class Build
    extend Forwardable
    def_delegators Hanami::Utils::String, :classify

    def initialize(tree)
      @tree = tree
    end

    def call(frag)
      node_klass(frag.kind).new(attributes(frag))
    end

    private

    attr_reader :tree

    def attributes(frag)
      frag
        .to_h
        .slice(:id, :abstract_id, :context_id, :body, :note)
        .merge(tree: tree)
    end

    def node_klass(kind)
      Umwelt::Node.const_get classify(kind)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
umwelt-0.2 lib/umwelt/node/build.rb
umwelt-0.1.1 lib/umwelt/node/build.rb
umwelt-0.1.0 lib/umwelt/node/build.rb