Sha256: d8edc491a9ca8568eb2b709b5195080221740c1d4b7f828ff9f54ec501541937
Contents?: true
Size: 1.49 KB
Versions: 4
Compression:
Stored size: 1.49 KB
Contents
require 'vedeu/parsing/text_adaptor' module Vedeu class HashParser # Convert a hash into a collection of interfaces. # # @param output [Hash] a collection of interface pairs of the # format: # # { # interface_1: "A block of text containing\n" \ # "new line characters.\n", # interface_2: "Some content destined for the " \ # "other interface.\n" # } # # becomes: # # { # interfaces: [ # { # name: 'interface_1', # lines: [{ # streams: { text: "A block of text containing" } # }, { # streams: { text: "new line characters." } # }] # }, { # name: 'interface_2', # lines: [{ # streams: { text: "Some content destined for the " \ # "other interface." } # }] # } # ] # } # # @return [Hash] def self.parse(output = {}) new(output).parse end def initialize(output = {}) @output = output end def parse { interfaces: interfaces } end private attr_reader :output def interfaces stringified_keys.map do |name, content| { name: name, lines: TextAdaptor.adapt(content) } end end def stringified_keys output.inject({}) { |a, (k, v)| a[k.to_s] = v; a } end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.1.0 | lib/vedeu/parsing/hash_parser.rb |
vedeu-0.0.42 | lib/vedeu/parsing/hash_parser.rb |
vedeu-0.0.41 | lib/vedeu/parsing/hash_parser.rb |
vedeu-0.0.40 | lib/vedeu/parsing/hash_parser.rb |