lib/osm/badge.rb in osm-0.6.0 vs lib/osm/badge.rb in osm-0.6.1
- old
+ new
@@ -324,13 +324,18 @@
# @return [Hash]
def gained_in_sections
count = {}
requirements.each do |field, data|
field = field.split('_')[0]
- count[field] ||= 0
- next if data.blank? || data[0].downcase.eql?('x')
- count[field] += 1
+ unless field.eql?('y')
+ count[field] ||= 0
+ next if data.blank? || data[0].downcase.eql?('x')
+ count[field] += 1
+ else
+ # A total 'section'
+ count['a'] = data.to_i
+ end
end
return count
end
# Check if this badge is due
@@ -342,12 +347,18 @@
# Check if this badge has been started
# @return [Boolean] whether the badge has been started by the member (always false if the badge has been completed)
def started?
unless badge.type == :staged
return false if completed?
- requirements.each do |key, value|
- return true unless value.blank? || value[0].downcase.eql?('x')
+ if badge.osm_key == 'adventure'
+ # Badge requires completing a number of activities
+ return (requirements['y_01'].to_i > 0)
+ else
+ # 'Normal' nonstaged badge
+ requirements.each do |key, value|
+ return true unless value.blank? || value[0].downcase.eql?('x')
+ end
end
else
# Staged badge
return (started > completed)
end
@@ -371,9 +382,10 @@
if (done < stages[index]) && (done > stages[index-1])
return stages[index]
end
end
else
+ # 'Normal' staged badge
start_group = 'abcde'[completed] # Requirements use the group letter to denote stage
started = 'z'
requirements.each do |key, value|
next if key[0] < start_group # This stage is marked as completed
next if key[0] > started # This stage is after the stage currently started