Sha256: 5dca4374efc63a347ab093b8e926d9a873f78931341f69bb8e8d7e15ab82dafe

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module Troo
  module External
    class CommentAdaptor
      class << self
        def adapt(resource)
          new(resource).adapted
        end
      end

      def initialize(resource)
        @resource = resource
      end

      def adapted
        {
          external_comment_id: external_comment_id,
          external_board_id:   external_board_id,
          external_card_id:    external_card_id,
          external_member_id:  external_member_id,
          date:                date,
          text:                text,
        }
      end

      private
      attr_reader :resource

      def external_comment_id
        resource.id
      end

      def external_board_id
        resource.data.fetch("board", {}).fetch("id", "")
      end

      def external_card_id
        resource.data.fetch("card",  {}).fetch("id", "")
      end

      def external_member_id
        resource.member_creator_id
      end

      def date
        resource.date.to_s
      end

      def text
        resource.data.fetch("text", "")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
troo-0.0.7 lib/troo/external/comment_adaptor.rb
troo-0.0.6 lib/troo/external/comment_adaptor.rb
troo-0.0.5 lib/troo/external/comment_adaptor.rb
troo-0.0.4 lib/troo/external/comment_adaptor.rb
troo-0.0.3 lib/troo/external/comment_adaptor.rb
troo-0.0.2 lib/troo/external/comment_adaptor.rb