Class: Osm::DueBadges
- Inherits:
-
Object
- Object
- Osm::DueBadges
- Defined in:
- lib/osm/due_badges.rb
Instance Attribute Summary collapse
-
#by_member ⇒ Hash
readonly
The due badges grouped by member.
-
#descriptions ⇒ Hash
readonly
Descriptions for each of the badges.
-
#totals ⇒ Hash
readonly
The total number of each badge which is due.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Check if there are no badges due.
-
#initialize(data) ⇒ DueBadges
constructor
Initialize a new Event using the hash returned by the API call.
Constructor Details
#initialize(data) ⇒ DueBadges
Initialize a new Event using the hash returned by the API call
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/osm/due_badges.rb', line 15 def initialize(data) data = {} unless data.is_a?(Hash) @pending = data['pending'].is_a?(Hash) ? Osm::symbolize_hash(data['pending']) : {} @descriptions = data['description'].is_a?(Hash) ? Osm::symbolize_hash(data['description']) : {} @pending.each_key do |key| @pending[key].each_with_index do |item, index| @pending[key][index] = item = Osm::symbolize_hash(item) item[:sid] = item[:sid].to_i item[:completed] = item[:completed].to_i end end @descriptions.each_key do |key| @descriptions[key] = Osm::symbolize_hash(@descriptions[key]) @descriptions[key][:section] = @descriptions[key][:section].to_sym @descriptions[key][:type] = @descriptions[key][:type].to_sym end @by_member = {} @totals = {} @pending.each_key do |key| @pending[key].each do |item| name = "#{item[:firstname]} #{item[:lastname]}" by_member[name] = [] if by_member[name].nil? badge = { :badge => key, :extra_information => item[:extra] } by_member[name].push badge @totals[key] = {} if @totals[key].nil? @totals[key][item[:extra]] = @totals[key][item[:extra]].to_i + 1 end end end |
Instance Attribute Details
#by_member ⇒ Hash (readonly)
Returns the due badges grouped by member.
6 7 8 |
# File 'lib/osm/due_badges.rb', line 6 def by_member @by_member end |
#descriptions ⇒ Hash (readonly)
Returns descriptions for each of the badges.
6 7 8 |
# File 'lib/osm/due_badges.rb', line 6 def descriptions @descriptions end |
#totals ⇒ Hash (readonly)
Returns the total number of each badge which is due.
6 7 8 |
# File 'lib/osm/due_badges.rb', line 6 def totals @totals end |
Instance Method Details
#empty? ⇒ Boolean
Check if there are no badges due
55 56 57 |
# File 'lib/osm/due_badges.rb', line 55 def empty? return @by_member.empty? end |