Class: Osm::Badges::DueBadges

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

Constant Summary

Constants inherited from Model

Model::SORT_BY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #<=>, #>, #>=, api_has_permission?, #between?, cache_delete, cache_exist?, cache_key, cache_read, cache_write, can_access_section?, #changed_attributes, configure, get_from_ids, has_access_to_section?, has_permission?, require_ability_to, require_access_to_section, require_permission, require_subscription, #reset_changed_attributes, #to_i, user_has_permission?

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