Skip to content

Commit

Permalink
Refactored printing date methods in card class to avoid duplication a…
Browse files Browse the repository at this point in the history
…nd maintain readability.
  • Loading branch information
jhallbachner authored and jhallbachner-mb committed Aug 21, 2016
1 parent 7db36e7 commit e971e55
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions lib/card.rb
Expand Up @@ -76,27 +76,11 @@ def all_legalities(date=nil)
end

def first_release_date(filter="all")
case filter
when "full"
@printings.select{|pr| !%w(promo masters).include?(pr.set_type) && pr.set_code != 'tpr'}.map(&:release_date)
.compact.min
when "expert"
@printings.select{|pr| %w(core expansion).include?(pr.set_type)}.map(&:release_date).compact.min
else
@printings.map(&:release_date).compact.min
end
@printings.select{|pr| verify_set_type(pr, filter)}.map(&:release_date).compact.min
end

def last_release_date(filter="all")
case filter
when "full"
@printings.select{|pr| !%w(promo masters).include?(pr.set_type) && pr.set_code != 'tpr'}.map(&:release_date)
.compact.max
when "expert"
@printings.select{|pr| %w(core expansion).include?(pr.set_type)}.map(&:release_date).compact.max
else
@printings.map(&:release_date).compact.max
end
@printings.select{|pr| verify_set_type(pr, filter)}.map(&:release_date).compact.max
end

private
Expand Down Expand Up @@ -163,4 +147,15 @@ def calculate_partial_color_identity
end
ci.uniq.join
end

def verify_set_type(pr, type)
case type
when "full"
!%w(promo masters).include?(pr.set_type) && pr.set_code != 'tpr'
when "expert"
%w(core expansion).include?(pr.set_type)
else
true
end
end
end

0 comments on commit e971e55

Please sign in to comment.