From 10fa8c63cb12fc5861464e7698715b8b42d3984d Mon Sep 17 00:00:00 2001 From: David Lindes Date: Wed, 29 Dec 2021 17:50:34 -0800 Subject: [PATCH] Parser#initialize: read file when filename given It seems natural to pass a filename to initialize, so if whatever we're given is a file that exists, read its contents instead of using it as string data directly. (It occurs to me that we may want to duplicate the string otherwise, but I'm unsure what other use cases might be present that I'm not thinking of, so I'm leaving that out for now.) Fixes #2 Note: Chosing to bump version to 0.2.2 because rubygems has a 0.2.1 from somewhere that I couldn't find. This change technically Copyright 2021 by David Lindes, and I agree to license it under the same terms as the rest of this repository. --- lib/quicken_parser/parser.rb | 3 ++- lib/quicken_parser/version.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/quicken_parser/parser.rb b/lib/quicken_parser/parser.rb index d94c517..e95053c 100644 --- a/lib/quicken_parser/parser.rb +++ b/lib/quicken_parser/parser.rb @@ -4,7 +4,8 @@ module QuickenParser class Parser #:nodoc: def initialize(source) - @input = source.respond_to?(:read) ? source.read : source + @input = source.respond_to?(:read) ? source.read : + File.exists?(source) ? File.open(source).read : source end def parse diff --git a/lib/quicken_parser/version.rb b/lib/quicken_parser/version.rb index 2965990..59c9725 100644 --- a/lib/quicken_parser/version.rb +++ b/lib/quicken_parser/version.rb @@ -1,3 +1,3 @@ module QuickenParser - VERSION = "0.2.0" + VERSION = "0.2.2" end