Class: TreasureData::Schema
- Inherits:
-
Object
- Object
- TreasureData::Schema
- Defined in:
- lib/td/client/model.rb
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
- #add_field(name, type) ⇒ Object
- #from_json(obj) ⇒ Object
-
#initialize(fields = []) ⇒ Schema
constructor
A new instance of Schema.
- #merge(schema) ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(fields = []) ⇒ Schema
Returns a new instance of Schema.
191 192 193 |
# File 'lib/td/client/model.rb', line 191 def initialize(fields=[]) @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
195 196 197 |
# File 'lib/td/client/model.rb', line 195 def fields @fields end |
Class Method Details
.parse(cols) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/td/client/model.rb', line 183 def self.parse(cols) fields = cols.split(',').map {|col| name, type, *_ = col.split(':') Field.new(name, type) } Schema.new(fields) end |
Instance Method Details
#add_field(name, type) ⇒ Object
197 198 199 |
# File 'lib/td/client/model.rb', line 197 def add_field(name, type) @fields << Field.new(name, type) end |
#from_json(obj) ⇒ Object
217 218 219 220 221 222 |
# File 'lib/td/client/model.rb', line 217 def from_json(obj) @fields = obj.map {|f| Field.new(f[0], f[1]) } self end |
#merge(schema) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/td/client/model.rb', line 201 def merge(schema) nf = @fields.dup schema.fields.each {|f| if i = nf.find_index {|sf| sf.name == f.name } nf[i] = f else nf << f end } Schema.new(nf) end |
#to_json(*args) ⇒ Object
213 214 215 |
# File 'lib/td/client/model.rb', line 213 def to_json(*args) @fields.map {|f| [f.name, f.type] }.to_json(*args) end |