class HQTrivia::Badge

The Badge Class. A very specific badge.

Public Class Methods

new(data) click to toggle source

@!visibility private

# File lib/hqtrivia/badge.rb, line 4
def initialize(data)
  @data = data
end

Public Instance Methods

completed?() click to toggle source

@return [true, false] the completion of this

# File lib/hqtrivia/badge.rb, line 44
def completed?
  @data['completed']
end
description() click to toggle source

@return [String] the description of this badge (shown in the app)

# File lib/hqtrivia/badge.rb, line 19
def description
  @data['description']
end
earned() click to toggle source

HQ API Returns 1/1/1970 if completed? is false. We'll return nil. @return [Time, nil] the time this was achieved

# File lib/hqtrivia/badge.rb, line 60
def earned
  return nil unless completed?

  Time.parse(@data['earnedAt'])
end
family() click to toggle source

@return [String] the family of this badge

# File lib/hqtrivia/badge.rb, line 24
def family
  @data['family']
end
id() click to toggle source

@return [Integer] the ID of this badge

# File lib/hqtrivia/badge.rb, line 9
def id
  @data['achievementId']
end
image_url() click to toggle source

@return [String] the image for this badge

# File lib/hqtrivia/badge.rb, line 34
def image_url
  @data['imageUrl']
end
last_updated() click to toggle source

@return [Time] the time this progress was last updated

# File lib/hqtrivia/badge.rb, line 49
def last_updated
  Time.at(@data['lastUpdated'] / 1000)
end
level() click to toggle source

@return [Integer] the level of this badge

# File lib/hqtrivia/badge.rb, line 29
def level
  @data['familyOrder'] + 1
end
name() click to toggle source

@return [String] the name of this badge (shown in the app)

# File lib/hqtrivia/badge.rb, line 14
def name
  @data['name']
end
progress() click to toggle source

@return [Float] the progress towards the next level. 100 if achieved.

# File lib/hqtrivia/badge.rb, line 39
def progress
  @data['progressPct']
end