Class: DataPackage::Resource
- Inherits:
-
Hash
- Object
- Hash
- DataPackage::Resource
show all
- Includes:
- Helpers
- Defined in:
- lib/datapackage/resource.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#base_path, #dereference_descriptor, #is_fully_qualified_url?, #is_safe_path?, #join_paths, #load_json, #resolve_json_reference
Constructor Details
#initialize(resource, base_path = '') ⇒ Resource
Returns a new instance of Resource.
9
10
11
12
13
14
15
16
17
|
# File 'lib/datapackage/resource.rb', line 9
def initialize(resource, base_path = '')
self.merge! dereference_descriptor(resource, base_path: base_path,
reference_fields: ['schema', 'dialect'])
apply_defaults!
@profile = DataPackage::Profile.new(self['profile'])
@name = self.fetch('name')
get_source!(base_path)
apply_table_defaults! if self.tabular?
end
|
Instance Attribute Details
#errors ⇒ Object
7
8
9
|
# File 'lib/datapackage/resource.rb', line 7
def errors
@errors
end
|
#name ⇒ Object
7
8
9
|
# File 'lib/datapackage/resource.rb', line 7
def name
@name
end
|
#profile ⇒ Object
7
8
9
|
# File 'lib/datapackage/resource.rb', line 7
def profile
@profile
end
|
#source ⇒ Object
7
8
9
|
# File 'lib/datapackage/resource.rb', line 7
def source
@source
end
|
Instance Method Details
#descriptor ⇒ Object
33
34
35
|
# File 'lib/datapackage/resource.rb', line 33
def descriptor
self.to_h
end
|
#inline? ⇒ Boolean
Also known as:
inline
37
38
39
|
# File 'lib/datapackage/resource.rb', line 37
def inline?
@source_type == 'inline'
end
|
#iter_errors ⇒ Object
29
30
31
|
# File 'lib/datapackage/resource.rb', line 29
def iter_errors
@profile.iter_errors(self){ |err| yield err }
end
|
#local? ⇒ Boolean
Also known as:
local
43
44
45
|
# File 'lib/datapackage/resource.rb', line 43
def local?
@source_type == 'local'
end
|
#miltipart? ⇒ Boolean
Also known as:
miltipart
55
56
57
|
# File 'lib/datapackage/resource.rb', line 55
def miltipart?
false
end
|
#remote? ⇒ Boolean
Also known as:
remote
49
50
51
|
# File 'lib/datapackage/resource.rb', line 49
def remote?
@source_type == 'remote'
end
|
#table ⇒ Object
70
71
72
|
# File 'lib/datapackage/resource.rb', line 70
def table
@table ||= TableSchema::Table.new(self.source, self['schema']) if tabular?
end
|
#tabular? ⇒ Boolean
Also known as:
tabular
61
62
63
64
65
66
|
# File 'lib/datapackage/resource.rb', line 61
def tabular?
tabular_profile = DataPackage::DEFAULTS[:resource][:tabular_profile]
return true if @profile.name == tabular_profile
return true if DataPackage::Profile.new(tabular_profile).valid?(self)
false
end
|
#valid? ⇒ Boolean
Also known as:
valid
19
20
21
|
# File 'lib/datapackage/resource.rb', line 19
def valid?
@profile.valid?(self)
end
|
#validate ⇒ Object
25
26
27
|
# File 'lib/datapackage/resource.rb', line 25
def validate
@profile.validate(self)
end
|