2015-09-14 04:02:52 +00:00
|
|
|
module GitHubChangelogGenerator
|
2015-09-15 18:38:41 +00:00
|
|
|
class ParserFile
|
2015-09-14 04:02:52 +00:00
|
|
|
def initialize(options)
|
|
|
|
@options = options
|
|
|
|
end
|
|
|
|
|
|
|
|
def file
|
2015-09-15 18:38:41 +00:00
|
|
|
File.expand_path(@options[:params_file] || ".github_changelog_generator")
|
2015-09-14 04:02:52 +00:00
|
|
|
end
|
|
|
|
|
2015-09-15 18:38:41 +00:00
|
|
|
def file?
|
|
|
|
File.exist?(file)
|
2015-09-14 04:02:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def file_open
|
|
|
|
File.open(file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse!
|
2015-09-15 18:38:41 +00:00
|
|
|
return unless file?
|
2015-09-14 04:02:52 +00:00
|
|
|
file_open.each do |line|
|
2015-09-15 18:38:41 +00:00
|
|
|
begin
|
|
|
|
key, value = line.split("=")
|
|
|
|
key_sym = key.sub("-", "_").to_sym
|
|
|
|
value = value.gsub(/[\n\r]+/, "")
|
|
|
|
value = true if value =~ (/^(true|t|yes|y|1)$/i)
|
|
|
|
value = false if value =~ (/^(false|f|no|n|0)$/i)
|
|
|
|
@options[key_sym] = value
|
|
|
|
rescue
|
|
|
|
raise "File #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
|
|
|
end
|
2015-09-14 04:02:52 +00:00
|
|
|
end
|
2015-09-15 18:38:41 +00:00
|
|
|
@options
|
2015-09-14 04:02:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|