Class: AppleData::DataFile::DataFileCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_data/data_file.rb

Overview

A specific "collection" inside a data file. Collections are enumerable groups of one type of item. The schema of each item is the same within a collection.

Instance Method Summary collapse

Constructor Details

#initialize(data_file, collection_name) ⇒ DataFileCollection

Returns a new instance of DataFileCollection.



104
105
106
107
108
# File 'lib/apple_data/data_file.rb', line 104

def initialize(data_file, collection_name)
  @data_file = data_file
  @collection_name = collection_name
  @collection_data = @data_file.data[@collection_name]
end

Instance Method Details

#dataObject



110
111
112
# File 'lib/apple_data/data_file.rb', line 110

def data
  @collection_data
end

#sort!Object



114
115
116
117
118
119
120
121
# File 'lib/apple_data/data_file.rb', line 114

def sort!
  case @collection_data
  when Array
    @collection_data.sort
  when Hash
    @collection_data = @collection_data.sort_by { |key, _value| key }.to_h
  end
end