Sha256: b6992d68fb3dcd1bdf0fbe5f7e7687220722fb428e686015b9f9b4430b676329

Contents?: true

Size: 1.36 KB

Versions: 15

Compression:

Stored size: 1.36 KB

Contents

require 'junoser/input'
require 'junoser/display/config_store'
require 'junoser/parser'
require 'junoser/transformer'

module Junoser
  module Display
    class Structure
      def initialize(io_or_string)
        @input = io_or_string
        @config = Junoser::Display::ConfigStore.new
      end

      def transform
        parser = Junoser::Parser.new
        transform = Junoser::Transformer.new

        config = Junoser::Input.new(@input).read.split("\n").map(&:strip)
        deactivated_lines = []

        config.each do |line|
          # .xsd doesn't include "apply-groups"
          apply_groups = trim_apply_groups(line)
          if line == 'set'
            @config << apply_groups
            next
          end

          if line =~ /^deactivate *(.*)/
            deactivated_lines << "#$1 #{apply_groups}".strip
            next
          end

          transformed = transform.apply(parser.parse(line))
          raise "ERROR: Failed to parse \"#{line}\"" unless transformed.is_a?(String)

          if apply_groups
            transformed << "\n#{apply_groups}"
          end

          @config << transformed
        end

        deactivated_lines.each {|l| @config.deactivate l }

        @config.to_s
      end

      private

      def trim_apply_groups(line)
        line.gsub! /\s+(apply-groups(-except)?\s+.*)/, ''
        return $1
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
junoser-0.6.0 lib/junoser/display/structure.rb
junoser-0.5.6 lib/junoser/display/structure.rb
junoser-0.5.5 lib/junoser/display/structure.rb
junoser-0.5.4 lib/junoser/display/structure.rb
junoser-0.5.3 lib/junoser/display/structure.rb
junoser-0.5.2 lib/junoser/display/structure.rb
junoser-0.5.1 lib/junoser/display/structure.rb
junoser-0.5.0 lib/junoser/display/structure.rb
junoser-0.4.7 lib/junoser/display/structure.rb
junoser-0.4.6 lib/junoser/display/structure.rb
junoser-0.4.5 lib/junoser/display/structure.rb
junoser-0.4.4 lib/junoser/display/structure.rb
junoser-0.4.3 lib/junoser/display/structure.rb
junoser-0.4.2 lib/junoser/display/structure.rb
junoser-0.4.1 lib/junoser/display/structure.rb