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
|
70
71
72
73
74
75
|
# File 'lib/datapackage/resource.rb', line 70
def
if !tabular
nil
end
get_table.
end
|
#inline? ⇒ Boolean
Also known as:
inline
37
38
39
|
# File 'lib/datapackage/resource.rb', line 37
def inline?
@source_type == 'inline'
end
|
#iter(*args, &block) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/datapackage/resource.rb', line 84
def iter(*args, &block)
if !tabular
message ='Methods iter/read are not supported for non tabular data'
raise ResourceException.new message
end
get_table.iter(*args, &block)
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
|
#read(*args, &block) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/datapackage/resource.rb', line 92
def read(*args, &block)
if !tabular
message ='Methods iter/read are not supported for non tabular data'
raise ResourceException.new message
end
get_table.read(*args, &block)
end
|
#remote? ⇒ Boolean
Also known as:
remote
49
50
51
|
# File 'lib/datapackage/resource.rb', line 49
def remote?
@source_type == 'remote'
end
|
#schema ⇒ Object
77
78
79
80
81
82
|
# File 'lib/datapackage/resource.rb', line 77
def schema
if !tabular
nil
end
get_table.schema
end
|
#table ⇒ Object
102
103
104
|
# File 'lib/datapackage/resource.rb', line 102
def table
get_table
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
|