class Uberous::Data
Constants
- ATTR_NAMES
Attributes
data_collection[R]
Public Class Methods
new(attrs = {})
click to toggle source
# File lib/uberous/uber.rb, line 36 def initialize(attrs = {}) @attrs = ATTR_NAMES.each_with_object({}) {|name, h| h[name] = attrs[name] if attrs.has_key?(name) } # slice @data_collection = Array(attrs[:data_collection]) end
Public Instance Methods
add_data(data)
click to toggle source
# File lib/uberous/uber.rb, line 50 def add_data(data) @data_collection << data end
add_link(rel, url, options = {})
click to toggle source
# File lib/uberous/uber.rb, line 54 def add_link(rel, url, options = {}) link = Data.new(options.merge(rel: rel, url: url)) add_data(link) end
to_hash()
click to toggle source
# File lib/uberous/uber.rb, line 59 def to_hash hash = @attrs.dup data = @data_collection.map(&:to_hash) hash[:data] = data unless data.empty? hash end