Created
October 18, 2020 23:27
-
-
Save jullle3/9a8b683cf6eb170a722536262871df98 to your computer and use it in GitHub Desktop.
just some homework
some_homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inp = " | |
#some_hashtag=1 | |
testval=2 | |
[Key=3] | |
" | |
def parse_racadm(reply) | |
parsed = {} | |
reply.each_line do |line| | |
sub_line_array = line.split('=') | |
if sub_line_array.length > 1 | |
if line.start_with? '[Key=' | |
parsed[:Key] = sub_line_array[1].strip[0..-2] | |
elsif sub_line_array[0].end_with? '[Key' | |
subkey = sub_line_array.slice!(0).strip.chomp(' [Key') | |
subvalue = '[Key=' + sub_line_array.join('=').strip | |
parsed[subkey] = subvalue | |
elsif line.start_with? "#" # Remove hashtags since we handle the read-only cases elsewhere (?) | |
sub_line_array[0][0] = "" | |
subkey = sub_line_array.slice!(0).strip.gsub(%r{\s+}, '') | |
subvalue = sub_line_array.join('=').strip | |
parsed[subkey] = subvalue | |
elsif !sub_line_array[0].start_with? '!!' | |
subkey = sub_line_array.slice!(0).strip.gsub(%r{\s+}, '') | |
subvalue = sub_line_array.join('=').strip | |
parsed[subkey] = subvalue | |
end | |
end | |
end | |
parsed | |
end | |
r = parse_racadm(inp) | |
puts r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment