diff --git a/README.md b/README.md index aa64b74..b94a8d9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +This is a solution for the following ruby test task [roonyx-tech/ruby-test-task](https://github.com/roonyx-tech/ruby-test-task) + # Ruby interview task ### Overview diff --git a/app/serializer.rb b/app/serializer.rb index 258be50..1df55aa 100644 --- a/app/serializer.rb +++ b/app/serializer.rb @@ -1,2 +1,40 @@ +# frozen_string_literal: true + class Serializer + @@attributes = {} + + class << self + def attribute(key, &block) + attributes[key] = block_given? ? block : nil + end + + def attributes + @@attributes[to_s] ||= {} + end + + def object + @@object + end + end + + def initialize(object) + @@object = object + end + + def serialize + serialized_data = {} + + attributes.each do |key, value| + serialized_data[key] = value ? value.call : object.send(key) + end + serialized_data + end + + def object + @@object + end + + def attributes + @@attributes[self.class.to_s] + end end