Sha256: 0305694cd2dd6814e7efd4a8e819cb8c4ea4e1e2f4858bb284cbab3cdfbaaa6c

Contents?: true

Size: 731 Bytes

Versions: 3

Compression:

Stored size: 731 Bytes

Contents

require 'vedeu/output/text_adaptor'

module Vedeu
  class RawParser
    def self.parse(attributes)
      new(attributes).parse
    end

    def initialize(attributes)
      @attributes = attributes
    end

    def parse
      { interfaces: interfaces }
    end

    private

    attr_reader :attributes

    def interfaces
      stringified_keys.map do |name, content|
        {
          name:  name,
          lines: lines(content)
        }
      end
    end

    def lines(content)
      if content.is_a?(Array) && content.first.is_a?(Hash)
        content
      else
        TextAdaptor.adapt(content)
      end
    end

    def stringified_keys
      attributes.inject({}) { |a, (k, v)| a[k.to_s] = v; a }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.1.6 lib/vedeu/output/raw_parser.rb
vedeu-0.1.5 lib/vedeu/output/raw_parser.rb
vedeu-0.1.4 lib/vedeu/output/raw_parser.rb