Class: DataPackage::Resource
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
Instance Method Summary collapse
- #dialect=(json) ⇒ Object
-
#each_row(&block) ⇒ Object
Future Note: For remote resources we should have a path and a url If the path is a file on disk then use it, otherwise assume that the path is a pointer to the destination of the URL data this makes it possible for scripts to rely on a file location.
-
#initialize(base_path, attrs = {}) ⇒ Resource
constructor
A new instance of Resource.
- #schema=(json) ⇒ Object
Methods included from AttrHelper::Serialization
Methods included from AttrHelper::Base
#attr_missing?, #attr_present?, #attr_required?, #attributes, included, #missing_attributes, #optional_attributes, #required_attributes, #write_attribute, #write_attributes
Constructor Details
#initialize(base_path, attrs = {}) ⇒ Resource
Returns a new instance of Resource.
27 28 29 30 |
# File 'lib/data_package/resource.rb', line 27 def initialize(base_path, attrs = {}) @base_path = base_path super(attrs) end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
25 26 27 |
# File 'lib/data_package/resource.rb', line 25 def base_path @base_path end |
Instance Method Details
#dialect=(json) ⇒ Object
36 37 38 |
# File 'lib/data_package/resource.rb', line 36 def dialect=(json) @dialect = Dialect.new(json) end |
#each_row(&block) ⇒ Object
Future Note:
For remote resources we should have a path *and* a url
If the path is a file on disk then use it, otherwise assume
that the path is a pointer to the destination of the URL data
this makes it possible for scripts to rely on a file location
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/data_package/resource.rb', line 48 def each_row(&block) case data_source_type when :data data.each(&block) when :path file_path = File.join(base_path, path) case format when 'csv' DataKit::CSV::Parser.new(file_path).each_row(&block) else raise "Unrecognized resource format #{format} for resource #{name}." end when :url raise "URL based resources are not yet supported" else raise "Resources require one of data, path or url keys to be specified" end end |