Class: DataPackage::Resource
- Inherits:
-
Hash
- Object
- Hash
- DataPackage::Resource
show all
- Defined in:
- lib/datapackage/resource.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource, base_path = '') ⇒ Resource
Returns a new instance of Resource.
4
5
6
|
# File 'lib/datapackage/resource.rb', line 4
def initialize(resource, base_path = '')
self.merge! resource
end
|
Class Method Details
.file_exists?(resource, base_path) ⇒ Boolean
30
31
32
33
34
|
# File 'lib/datapackage/resource.rb', line 30
def self.file_exists?(resource, base_path)
path = resource['path']
path = File.join(base_path, path) if base_path != ''
File.exists?(path)
end
|
.is_url?(resource, base_path) ⇒ Boolean
36
37
38
39
|
# File 'lib/datapackage/resource.rb', line 36
def self.is_url?(resource, base_path)
return true if resource['url'] != nil && resource['path'] == nil && resource['data'] == nil
return true if base_path.start_with?('http')
end
|
.load(resource, base_path = '') ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/datapackage/resource.rb', line 8
def self.load(resource, base_path = '')
if is_url?(resource, base_path)
RemoteResource.new(resource, base_path)
else
if resource['data']
InlineResource.new(resource)
else
if file_exists?(resource, base_path)
LocalResource.new(resource, base_path)
elsif resource['url']
RemoteResource.new(resource, base_path)
end
end
end
end
|
Instance Method Details
#table ⇒ Object
41
42
43
|
# File 'lib/datapackage/resource.rb', line 41
def table
@table ||= JsonTableSchema::Table.new(CSV.parse(data), self['schema']) if self['schema']
end
|