How to get the co-ordinates to scroll up and down

I’m using ruby, so it may have typo’s

void swipeUpElement(AppiumDriver driver, MobileElement element, int duration){
    int topY = element.getLocation().getY()
    int bottomY = topY + element.getSize().getHeight()
    int centerX = element.getLocation().getX() + (element.getSize().getWidth()/2)
    driver.swipe(centerX, bottomY, centerX, topY, duration);
}

For a swipe down of the height of element its the same logic. Just invert the Y