Sha256: b421e1d506d5bafbe7b8a23d75237b4d1865a5312c295824cab127bd4a057a31
Contents?: true
Size: 634 Bytes
Versions: 3
Compression:
Stored size: 634 Bytes
Contents
module Nzbmatrix class ApiResponseParser def parse(response) parsed = response.split(/^\|$/).map do |block| parse_block(block) end parsed.reject do |hash| hash.empty? end end def parse_block(block) block.split("\n").inject({}) do |h, line| if (parsed = parse_line(line)) key, value = parsed h[key] = value end h end end def parse_line(line) unless line.empty? key, value = line.split(":", 2) value.gsub!(/;$/, "") unless value.nil? [key, value] end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nzbmatrix-0.0.4 | lib/nzbmatrix/api_response_parser.rb |
nzbmatrix-0.0.3 | lib/nzbmatrix/api_response_parser.rb |
nzbmatrix-0.0.2 | lib/nzbmatrix/api_response_parser.rb |