Module: Roar::Representer::JSON::CollectionJSON::DataMethods
- Defined in:
- lib/roar/representer/json/collection_json.rb
Instance Method Summary collapse
Instance Method Details
#from_hash(hash, *args) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/roar/representer/json/collection_json.rb', line 175 def from_hash(hash, *args) data = {} hash.delete("data").collect do |item| data[item["name"]] = item["value"] end super(hash.merge!(data)) end |
#to_hash ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/roar/representer/json/collection_json.rb', line 162 def to_hash(*) hash = super.tap do |hsh| data = [] hsh.keys.each do |n| next if ["href", "links"].include?(n) v = hsh.delete(n.to_s) data << {:name => n, :value => v} # TODO: get :prompt from Definition. end hsh[:data] = data end end |