github-changelog-generator/lib/github_changelog_generator/parser_file.rb

37 lines
834 B
Ruby
Raw Normal View History

module GitHubChangelogGenerator
2015-09-15 18:38:41 +00:00
class ParserFile
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")
end
2015-09-15 18:38:41 +00:00
def file?
File.exist?(file)
end
def file_open
File.open(file)
end
def parse!
2015-09-15 18:38:41 +00:00
return unless file?
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
end
2015-09-15 18:38:41 +00:00
@options
end
end
end