class ITGlue::Client::Mapper
Public Class Methods
map(raw_data)
click to toggle source
# File lib/itglue/client/mapper.rb, line 6 def self.map(raw_data) self.new(raw_data).format end
new(raw_data)
click to toggle source
# File lib/itglue/client/mapper.rb, line 10 def initialize(raw_data) @raw_data = raw_data end
Public Instance Methods
format()
click to toggle source
# File lib/itglue/client/mapper.rb, line 14 def format collection? ? format_collection(@raw_data) : format_object(@raw_data) end
Private Instance Methods
collection?()
click to toggle source
# File lib/itglue/client/mapper.rb, line 20 def collection? @raw_data.is_a?(Array) end
format_collection(data)
click to toggle source
# File lib/itglue/client/mapper.rb, line 24 def format_collection(data) data.map { |d| format_object(d) } end
format_object(data)
click to toggle source
# File lib/itglue/client/mapper.rb, line 28 def format_object(data) { id: data['id'].to_i, type: data['type'], attributes: transform_keys(data['attributes']) } end
transform_keys(attributes)
click to toggle source
# File lib/itglue/client/mapper.rb, line 36 def transform_keys(attributes) attributes.map { |key, value| [key.underscore.to_sym, value] }.to_h end