Sha256: ee9b2adc356bd2c94fa21e2620cbc44fcdbb0be241bba98020ee6388e55074d2

Contents?: true

Size: 734 Bytes

Versions: 44

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

module SublimeTextKit
  module Snippets
    KEY_MAP = {
      "content" => :content,
      "tabTrigger" => :trigger,
      "description" => :description,
      "scope" => :scope
    }.freeze

    # Defines a snippet record.
    Model = Struct.new(*KEY_MAP.values, keyword_init: true) do
      def self.for document, key_map: KEY_MAP
        root = document.root

        return new unless root

        root.elements
            .reduce({}) { |attributes, element| attributes.merge element.name => element.text }
            .transform_keys(key_map)
            .then { |attributes| new(**attributes) }
      end

      def initialize *arguments
        super
        freeze
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
sublime_text_kit-18.0.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.6.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.5.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.4.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.3.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.2.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.1.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.0.1 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-17.0.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-16.5.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-16.3.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-16.2.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-16.1.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-16.0.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-15.2.1 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-15.2.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-15.1.0 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-15.0.3 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-15.0.2 lib/sublime_text_kit/snippets/model.rb
sublime_text_kit-15.0.1 lib/sublime_text_kit/snippets/model.rb