Sha256: 4c87bbe5b4bd0e6c9ffeeff35b28c86b635b2dc2034ea694a306b5d36820e533

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module LaunchPass
  class User
    attr_reader :email
    attr_reader :first_name
    attr_reader :last_name
    attr_reader :avatar_url
    attr_reader :username

    def initialize(info_hash)
      @info_hash = info_hash
      @email = @info_hash["email"]
      @first_name = @info_hash["first_name"]
      @last_name = @info_hash["last_name"]
      @avatar_url = @info_hash["avatar_url"]
      @username = @info_hash["username"]
    end

    def member_of?(team_name)
      teams.include?(team_name)
    end

    def has_product?(product_name, wildcard = true)
      if !wildcard
        products.include?(product_name)
      else
        products.each do |product|
          return true if product =~ /#{Regexp.escape(product_name)}/
        end
        false
      end
    end

    def admin?
      member_of?('Admins')
    end

    def teams
      if @info_hash["teams"]
        @teams ||= @info_hash["teams"].map do |team_hash|
          team_hash["name"]
        end
      end
    end

    def products
      if @info_hash["products"]
        @products ||= @info_hash["products"].map do |product|
          product["name"]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-launch-pass-0.0.2 lib/launch_pass/user.rb