Sha256: f65467fb4fc68da6cf3e01072b255a23e5c8c644032edb20f16aff6d52eda9c2

Contents?: true

Size: 618 Bytes

Versions: 4

Compression:

Stored size: 618 Bytes

Contents

module LensProtocol
  module OMA
    class Parser
      def parse oma_str, types: {}
        types = TYPES.merge(types)
        normalize_line_endings(oma_str)
          .split("\n")
          .reduce(Message.new) { |message, line| parse_line line, message, types }
      end

      private

      def parse_line line, message, types
        raise ParsingError.new('The label separator is missing', line) unless line.include?('=')
        label, = line.split('=')
        types[label].parse(line, message)
      end

      def normalize_line_endings str
        str.to_s.gsub /\r\n?/, "\n"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lens_protocol-0.1.3 lib/lens_protocol/oma/parser.rb
lens_protocol-0.1.2 lib/lens_protocol/oma/parser.rb
lens_protocol-0.1.1 lib/lens_protocol/oma/parser.rb
lens_protocol-0.1.0 lib/lens_protocol/oma/parser.rb