# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=ruby-unicode-display_width
_pkgname="${pkgname#ruby-}"
pkgver=2.5.0
pkgrel=1
pkgdesc='Determines the monospace display width of a string in Ruby'
arch=('any')
url='https://github.com/janlelis/unicode-display_width'
license=('MIT')
depends=('ruby')
makedepends=('git' 'ruby-rdoc')
checkdepends=('ruby-rake' 'ruby-rspec' 'ruby-unicode-emoji')
options=('!emptydirs')
_commit='e59c4238b2eb32281b6349fcdf81d8a0169e3252'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

build() {
  cd "$pkgname"

  gem build "$_pkgname.gemspec" 
}

check() {
  cd "$pkgname"

  rake test
}

package() {
  cd "$pkgname"

  local _gemdir="$(ruby -e'puts Gem.default_dir')"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$_pkgname-$pkgver.gem"

  # delete cache
  rm -vrf "$pkgdir/$_gemdir/cache"

  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname"
  ln -sf "$_gemdir/gems/$_pkgname-$pkgver/MIT-LICENSE.txt" "$pkgdir/usr/share/licenses/$pkgname"
}
