Sha256: 081190b237280a486cc0f9e1fce85389a90bd0ac8a4ea5977cba3c39d4e32039

Contents?: true

Size: 1.26 KB

Versions: 14

Compression:

Stored size: 1.26 KB

Contents

# Copyright (c) 2020 Jerome Arbez-Gindre
# frozen_string_literal: true

require('aasm')

module DefMastership
  # DefMastership definition: contains all data of a definition
  class DefinitionParser
    include AASM

    def initialize(document)
      @document = document
    end

    aasm do
      state :idle, initial: true
      state :wait_content
      state :in_block
      state :single_para

      event :new_definition do
        transitions from: :idle, to: :wait_content, after: ->(*args) { @document.add_new_definition(*args) }
      end

      event :block_delimiter do
        transitions from: :wait_content,                 to: :in_block
        transitions from: %i[in_block idle single_para], to: :idle
      end

      event :new_line do
        transitions from: %i[wait_content single_para],
                    to: :single_para,
                    after: ->(*args) { @document.add_line(*args) }
        transitions from: :in_block,
                    to: :in_block,
                    after: ->(*args) { @document.add_line(*args) }
        transitions from: :idle, to: :idle
      end

      event :empty_line do
        transitions from: %i[wait_content single_para idle], to: :idle
        transitions from: :in_block, to: :in_block
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
defmastership-1.0.19 lib/defmastership/definition_parser.rb
defmastership-1.0.18 lib/defmastership/definition_parser.rb
defmastership-1.0.17 lib/defmastership/definition_parser.rb
defmastership-1.0.16 lib/defmastership/definition_parser.rb
defmastership-1.0.15 lib/defmastership/definition_parser.rb
defmastership-1.0.14 lib/defmastership/definition_parser.rb
defmastership-1.0.13 lib/defmastership/definition_parser.rb
defmastership-1.0.12 lib/defmastership/definition_parser.rb
defmastership-1.0.11 lib/defmastership/definition_parser.rb
defmastership-1.0.10 lib/defmastership/definition_parser.rb
defmastership-1.0.9 lib/defmastership/definition_parser.rb
defmastership-1.0.8 lib/defmastership/definition_parser.rb
defmastership-1.0.7 lib/defmastership/definition_parser.rb
defmastership-1.0.6 lib/defmastership/definition_parser.rb