Class: Osm::Badges::DueBadges

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/badges.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Constructor Details

#initializeObject

Initialize a new DueBadges

Parameters:

  • attributes (Hash)

    The hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)


# File 'lib/osm/badges.rb', line 140

Instance Attribute Details

#badge_namesHash

Returns name to display for each of the badges.

Returns:

  • (Hash)

    name to display for each of the badges


111
# File 'lib/osm/badges.rb', line 111

attribute :badge_names, :default => {}

#by_memberHash

Returns the due badges grouped by member.

Returns:

  • (Hash)

    the due badges grouped by member


111
# File 'lib/osm/badges.rb', line 111

attribute :badge_names, :default => {}

#member_namesHash

Returns the name to display for each member.

Returns:

  • (Hash)

    the name to display for each member


111
# File 'lib/osm/badges.rb', line 111

attribute :badge_names, :default => {}

Instance Method Details

#empty?Boolean

Check if there are no badges due

Returns:

  • (Boolean)

147
148
149
# File 'lib/osm/badges.rb', line 147

def empty?
  return by_member.empty?
end

#totalsHash

Calculate the total number of badges needed

Returns:

  • (Hash)

    the total number of each badge which is due


153
154
155
156
157
158
159
160
161
162
# File 'lib/osm/badges.rb', line 153

def totals()
  totals = {}
  by_member.each do |member_name, badges|
    badges.each do |badge|
      totals[badge] ||= 0
      totals[badge] += 1
    end
  end
  return totals
end