Last active
August 29, 2015 14:02
-
-
Save Theminijohn/564ce8ebf3577aee3014 to your computer and use it in GitHub Desktop.
This file contains 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
# 1st Example | |
raw_metas = file_content.scan( /\A\/\/\s==UserScript==(\w|\W)*\/\/\s==\/UserScript==$/ ) | |
raw_metas.split(/\r\n|\n|\r/).each do |line_with_meta| | |
#each line is structured like @attribute<space>value | |
end | |
#so in this loop, we need another regex to get the attribute's name, and the value | |
# 2nd Example | |
raw_metas.split(/\r\n|\n|\r/).each do |line_with_meta| | |
attribute_name = line_with_data.scan(/@\w+/) | |
end | |
# 3nd Example | |
raw_metas.split(/\r\n|\n|\r/).each do |line_with_meta| | |
attribute_name = line_with_data.scan(/@\w+/) | |
value = line_with_data.sub("// #{attribute_name}", '').strip | |
end | |
# 4th Example | |
metas = {} | |
raw_metas.split(/\r\n|\n|\r/).each do |line_with_meta| | |
attribute_name = line_with_data.scan(/@\w+/) | |
value = line_with_data.sub("// #{attribute_name}", '').strip | |
metas[attribute_name.sub('@', '').to_sym] = value | |
end | |
# Last Example | |
metas = {} | |
raw_metas.split(/\r\n|\n|\r/).each do |line_with_meta| | |
attribute_name = line_with_data.scan(/@\w+/) | |
value = line_with_data.sub("// #{attribute_name}", '').strip | |
if metas[attribute_name.sub('@', '').to_sym].present? | |
metas[attribute_name.sub('@', '').to_sym] = [ metas[attribute_name.sub('@', '').to_sym], value].flatten | |
else | |
metas[attribute_name.sub('@', '').to_sym] = value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment