lib/quandl/format/dataset/load.rb in quandl_format-0.1.5 vs lib/quandl/format/dataset/load.rb in quandl_format-0.1.6
- old
+ new
@@ -36,12 +36,13 @@
nodes << { attributes: '', data: '', line: line_index } if section_type == :data
# update the section to attributes
section_type = :attributes
# have we reached the end of the attributes?
- elsif line[0] == '-'
+ elsif line == '-'
# update the section to data
+ nodes[-1][:data_line] = line_index + 1
section_type = :data
# skip to the next line
next
end
# add the line to it's section in the current node.
@@ -75,33 +76,47 @@
datasets
end
def parse_yaml_attributes(node)
YAML.load( node[:attributes] ).symbolize_keys!
- rescue => e
- message = "Error: Dataset starting at line #{node[:line]}\n"
- message += "#{$!}\n"
- message += "--"
- Quandl::Logger.error(message)
+ rescue => err
+ log_yaml_parse_error(node, err)
nil
end
def node_to_dataset(node)
Quandl::Format::Dataset.new( node[:attributes] )
- rescue => e
+ rescue => err
+ log_dataset_error(node, err)
+ end
+
+ def attribute_format
+ /^([a-z0-9_]+): (.+)/
+ end
+
+ def log_yaml_parse_error(node, err)
+ message = "Attribute parse error at line #{ node[:line] + err.line } column #{err.column}. #{err.problem} (#{err.class})\n"
+ message += "Did you forget to delimit the meta data section from the data section with a one or more dashes ('-')?\n" unless node[:attributes] =~ /^-/
+ message += "--"
+ Quandl::Logger.error(message)
+ end
+
+ def log_dataset_error( node, err )
message = ''
message += node[:attributes][:source_code] + '/' if node[:attributes][:source_code].present?
message += node[:attributes][:code] + ' '
- message += "error around line #{node[:line]} \n"
- message += "#{$!}\n"
+ # include specific line if available
+ if err.respond_to?(:line)
+ message += "error at line #{node[:data_line].to_i + err.line.to_i}\n"
+ else
+ message += "error around line #{node[:line]}\n"
+ end
+ # include original error
+ message += "#{$!} (#{err.class})\n"
message += "--"
Quandl::Logger.error(message)
nil
end
- def attribute_format
- /^([a-z0-9_]+): (.+)/
- end
-
end
end
\ No newline at end of file