Class: Uberous::Uber
- Inherits:
-
Object
- Object
- Uberous::Uber
- Defined in:
- lib/uberous/uber.rb
Instance Attribute Summary collapse
-
#data_collection ⇒ Object
readonly
Returns the value of attribute data_collection.
-
#error_data_collection ⇒ Object
readonly
Returns the value of attribute error_data_collection.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #add_data(data) ⇒ Object
- #add_error_data(data) ⇒ Object
- #add_link(rel, url, options = {}) ⇒ Object
-
#initialize(data_collection = [], error_data_collection = [], version = '1.0') ⇒ Uber
constructor
A new instance of Uber.
- #to_hash ⇒ Object
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_collection ⇒ Object (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_collection ⇒ Object (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 |
#version ⇒ Object (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 |
#add_link(rel, url, options = {}) ⇒ Object
18 19 20 21 |
# File 'lib/uberous/uber.rb', line 18 def add_link(rel, url, = {}) link = Data.new(.merge(rel: rel, url: url)) add_data(link) end |
#to_hash ⇒ Object
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 |