Class: Uberous::Uber

Inherits:
Object
  • Object
show all
Defined in:
lib/uberous/uber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_collection = [], error_data_collection = [], version = '1.0') ⇒ Uber

Returns a new instance of Uber.



4
5
6
7
8
# File 'lib/uberous/uber.rb', line 4

def initialize(data_collection = [], error_data_collection = [], version = '1.0')
  @data_collection = data_collection
  @error_data_collection = error_data_collection
  @version = version
end

Instance Attribute Details

#data_collectionObject (readonly)

Returns the value of attribute data_collection.



3
4
5
# File 'lib/uberous/uber.rb', line 3

def data_collection
  @data_collection
end

#error_data_collectionObject (readonly)

Returns the value of attribute error_data_collection.



3
4
5
# File 'lib/uberous/uber.rb', line 3

def error_data_collection
  @error_data_collection
end

#versionObject (readonly)

Returns the value of attribute version.



3
4
5
# File 'lib/uberous/uber.rb', line 3

def version
  @version
end

Instance Method Details

#add_data(data) ⇒ Object



10
11
12
# File 'lib/uberous/uber.rb', line 10

def add_data(data)
  @data_collection << data
end

#add_error_data(data) ⇒ Object



14
15
16
# File 'lib/uberous/uber.rb', line 14

def add_error_data(data)
  @error_data_collection << data
end


18
19
20
21
# File 'lib/uberous/uber.rb', line 18

def add_link(rel, url, options = {})
  link = Data.new(options.merge(rel: rel, url: url))
  add_data(link)
end

#to_hashObject



23
24
25
26
27
28
29
30
# File 'lib/uberous/uber.rb', line 23

def to_hash
  data = @data_collection.map(&:to_hash)
  error = @error_data_collection.map(&:to_hash)
  uber = { version: @version }
  uber[:data] = data unless data.empty?
  uber[:error] = error unless error.empty?
  { uber: uber }
end