Sha256: 218f97c1cfb8c720f1a805fdc35e1d1c4a603a14df0caf9b2efbc053d2390362

Contents?: true

Size: 730 Bytes

Versions: 5

Compression:

Stored size: 730 Bytes

Contents

module Line
  module Bot
    module Event
      class Postback
        attr_reader :action, :params

        def initialize(src)
          super
          set_instance_variables
        end

        private

        # dataプロパティからインスタンス変数に設定する。
        #
        # action 'path/to/command'
        # params '{product_id: 1, order_num: 3}'
        def set_instance_variables
          data =
            postback.data
                    .split('&')
                    .map { |s| s.split('=') }
                    .each_with_object({}) { |(key, val), hash| hash[key.to_sym] = val }

          @action = data.delete :action
          @params = data
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pleiades-0.1.6 lib/pleiades/core_ext/line/bot/event/postback.rb
pleiades-0.1.5 lib/pleiades/core_ext/line/bot/event/postback.rb
pleiades-0.1.4 lib/pleiades/core_ext/line/bot/event/postback.rb
pleiades-0.1.3 lib/pleiades/core_ext/line/bot/event/postback.rb
pleiades-0.1.2 lib/pleiades/core_ext/line/bot/event/postback.rb