lib/maprename/content_parser.rb in maprename-0.1.0 vs lib/maprename/content_parser.rb in maprename-0.1.1
- old
+ new
@@ -5,21 +5,27 @@
def initialize(config, file)
@config = config
@file = file
@content = read_file_content(file)
+
+ debug " ContentParser: #@config"
end
def parse!(context)
config[:fields].each do |field_definition|
+ debug " ContentParser field definition: #{field_definition}"
fields = @content.match(Regexp.new(field_definition[:pattern])).to_a[1..-1]
+ debug " ContentParser fields: #{fields}"
eval_var_definition(fields, field_definition, context)
end
end
def eval_var_definition(fields, field_definition, context)
value = field_definition[:value].gsub(/\$(\d+)/, fields[$1.to_i - 1])
context.instance_eval "self.#{field_definition[:name]} = #{value.inspect}"
+ debug " ContentParser value: #{value}"
+ debug " ContentParser context: #{context}"
end
def read_file_content(file)
encoding = config[:encoding] || 'UTF-8'
content = IO.read(file, encoding: encoding)