Class: Yamori::Schema::Fields

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/yamori/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Fields

Returns a new instance of Fields.



255
256
257
# File 'lib/yamori/schema.rb', line 255

def initialize(schema)
  @fields = schema['fields'].map{|h| Field.new(**h)}
end

Instance Method Details

#each(&block) ⇒ Object



259
260
261
# File 'lib/yamori/schema.rb', line 259

def each(&block)
  fields.each &block
end

#find_by(name: nil, label: nil) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
# File 'lib/yamori/schema.rb', line 267

def find_by(name: nil, label: nil)
  return nil if name.nil? && label.nil?

  attr_name = name.nil? ? :label : :name
  val       = name || label

  find do |field|
    attr_val = field.__send__(attr_name.to_sym)
    attr_val == val.to_s
  end
end

#labelsObject



287
288
289
# File 'lib/yamori/schema.rb', line 287

def labels
  map(&:label)
end

#name_and_labelsObject



279
280
281
# File 'lib/yamori/schema.rb', line 279

def name_and_labels
  map{|field| [field.name, field.label]}
end

#namesObject



283
284
285
# File 'lib/yamori/schema.rb', line 283

def names
  map(&:name)
end

#to_aObject



263
264
265
# File 'lib/yamori/schema.rb', line 263

def to_a
  fields
end