<commit_before>module Appium
  # Perform a series of gestures, one after another.  Gestures are chained
  # together and only performed when `perform()` is called.
  #
  # Each method returns the object itself, so calls can be chained.
  #
  # ```ruby
  # action = TouchAction.new.press(x: 45, y: 100).wait(5).release
  # action.perform
  class TouchAction
    ACTIONS         = [:move_to, :long_press, :double_tap, :two_finger_tap, :press, :release, :tap, :wait, :perform].freeze
    COMPLEX_ACTIONS = [:swipe].freeze

    class << self
      COMPLEX_ACTIONS.each do |action|
        define_method(action) do |opts|
          auto_perform = opts.delete(:auto_perform) { |_k| true }
          ta           = TouchAction.new
          ta.send(action, opts)
          return ta unless auto_perform
          ta.perform
        end
      end
    end

    attr_reader :actions

    def initialize
      @actions = []
    end

    # Move to the given co-ordinates.
    # @option opts [integer] :x x co-ordinate to move to.
    # @option opts [integer] :y y co-ordinate to move to.
    # @option opts [WebDriver::Element] Element to scope this move within.
    def move_to(opts)
      opts = args_with_ele_ref(opts)
      chain_method(:moveTo, opts)
    end

    # Press down for a specific duration.
    # @option element [WebDriver::Element] the element to press.
    # @option x [integer] x co-ordinate to press on.
    # @option y [integer] y co-ordinate to press on.
    # @option duration [integer] Number of milliseconds to press.
    def long_press(opts)
      args = opts.select { |k, _v| [:element, :x, :y, :duration].include? k }
      args = args_with_ele_ref(args)
      chain_method(:longPress, args) # longPress is what the appium server expects
    end

    # Press a finger onto the screen.  Finger will stay down until you call
    # `release`.
    #
    # @option opts [WebDriver::Element] :element (Optional) Element to press within.
    # @option opts [integer] :x x co-ordinate to press on
    # @option opts [integer] :y y co-ordinate to press on
    def press(opts)
      args = opts.select { |k, _v| [:element, :x, :y].include? k }
      args = args_with_ele_ref(args)
      chain_method(:press, args)
    end

    # Remove a finger from the screen.
    #
    # @option opts [WebDriver::Element] :element (Optional) Element to release from.
    # @option opts [integer] :x x co-ordinate to release from
    # @option opts [integer] :y y co-ordinate to release from
    def release(opts = nil)
      args = args_with_ele_ref(opts) if opts<commit_msg>add documentation for alternative long_press method (#440)<commit_after>module Appium
  # Perform a series of gestures, one after another.  Gestures are chained
  # together and only performed when `perform()` is called.
  #
  # Each method returns the object itself, so calls can be chained.
  #
  # ```ruby
  # action = TouchAction.new.press(x: 45, y: 100).wait(5).release
  # action.perform
  class TouchAction
    ACTIONS         = [:move_to, :long_press, :double_tap, :two_finger_tap, :press, :release, :tap, :wait, :perform].freeze
    COMPLEX_ACTIONS = [:swipe].freeze

    class << self
      COMPLEX_ACTIONS.each do |action|
        define_method(action) do |opts|
          auto_perform = opts.delete(:auto_perform) { |_k| true }
          ta           = TouchAction.new
          ta.send(action, opts)
          return ta unless auto_perform
          ta.perform
        end
      end
    end

    attr_reader :actions

    def initialize
      @actions = []
    end

    # Move to the given co-ordinates.
    # @option opts [integer] :x x co-ordinate to move to.
    # @option opts [integer] :y y co-ordinate to move to.
    # @option opts [WebDriver::Element] Element to scope this move within.
    def move_to(opts)
      opts = args_with_ele_ref(opts)
      chain_method(:moveTo, opts)
    end

    # Press down for a specific duration.
    # Alternatively, you can use `press(...).wait(...).release()` instead of `long_press` if duration doesn't work well.
    # https://github.com/appium/ruby_lib/issues/231#issuecomment-269895512
    # e.g. Appium::TouchAction.new.press(x: 280, y: 530).wait(2000).release.perform
    #
    # @option element [WebDriver::Element] the element to press.
    # @option x [integer] x co-ordinate to press on.
    # @option y [integer] y co-ordinate to press on.
    # @option duration [integer] Number of milliseconds to press.
    def long_press(opts)
      args = opts.select { |k, _v| [:element, :x, :y, :duration].include? k }
      args = args_with_ele_ref(args)
      chain_method(:longPress, args) # longPress is what the appium server expects
    end

    # Press a finger onto the screen.  Finger will stay down until you call
    # `release`.
    #
    # @option opts [WebDriver::Element] :element (Optional) Element to press within.
    # @option opts [integer] :x x co-ordinate to press on
    # @option opts [integer] :y y co-ordinate to press on
    def press(opts)
      args = opts.select { |k, _v| [:element, :x, :y].include? k }
      args = args_with_ele_ref(args)
      chain_method(:press, args)
    end

    # Remove a finger from the screen.
    #
    # @option opts [WebDriver::Element] :element (Optional) Element to release from.
    # @option opts [integer] :x x co-ordinate to release from
    # @option opts [integer] :y y co-ordinate to release from
    def release(opts = nil)
      args = args_with_ele_ref(opts) if opts
{'fraction_non_alphanumeric': 0.1064569233583318, 'fraction_numerical': 0.006767880007316627, 'mean_word_length': 2.7814661134163208, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5201721', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1682, 'n_words': 580}