Sha256: 7a9005f695aff1b3f2665b4bf87ecbeb33c19e0a937b6a29b0d820f69cd33851

Contents?: true

Size: 1.35 KB

Versions: 8

Compression:

Stored size: 1.35 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\s+.*)/, ''
        return $1
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
junoser-0.4.0 lib/junoser/display/structure.rb
junoser-0.3.13 lib/junoser/display/structure.rb
junoser-0.3.12 lib/junoser/display/structure.rb
junoser-0.3.11 lib/junoser/display/structure.rb
junoser-0.3.10 lib/junoser/display/structure.rb
junoser-0.3.9 lib/junoser/display/structure.rb
junoser-0.3.8 lib/junoser/display/structure.rb
junoser-0.3.7 lib/junoser/display/structure.rb