Skip to content

Commit

Permalink
Extract Method
Browse files Browse the repository at this point in the history
A common subexpression in subclasses of NomenclaturalRank has been extracted into collect_descentants_to_s class method at NomenclaturalRank class.
  • Loading branch information
LocoDelAssembly committed Jan 20, 2014
1 parent 560d4f8 commit 0fd0567
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 8 deletions.
12 changes: 12 additions & 0 deletions app/models/nomenclatural_rank.rb
Expand Up @@ -65,5 +65,17 @@ def self.abbreviation
def self.valid_parents
[]
end

private
def self.collect_to_s(*args)
args.collect{|arg| arg.to_s}
end
def self.collect_descentants_to_s(*classes)
ans = []
classes.each do |klass|
ans += klass.descendants.collect{|k| k.to_s}
end
ans
end

end
4 changes: 3 additions & 1 deletion app/models/nomenclatural_rank/icn/family_group.rb
Expand Up @@ -5,6 +5,8 @@ def self.validate_name_format(taxon_name)
end

def self.valid_parents
NomenclaturalRank::Icn::HigherClassificationGroup.descendants.collect{|t| t.to_s} + NomenclaturalRank::Icn::FamilyGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Icn::HigherClassificationGroup,
NomenclaturalRank::Icn::FamilyGroup)
end
end
4 changes: 3 additions & 1 deletion app/models/nomenclatural_rank/icn/genus_group.rb
Expand Up @@ -10,6 +10,8 @@ def parent_rank
end

def self.valid_parents
NomenclaturalRank::Icn::FamilyGroup.descendants.collect{|t| t.to_s} + NomenclaturalRank::Icn::GenusGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Icn::FamilyGroup,
NomenclaturalRank::Icn::GenusGroup)
end
end
Expand Up @@ -6,7 +6,8 @@ def self.validate_name_format(taxon_name)
end

def self.valid_parents
NomenclaturalRank::Icn::HigherClassificationGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Icn::HigherClassificationGroup)
end

end
Expand Up @@ -6,6 +6,8 @@ def self.validate_name_format(taxon_name)
end

def self.valid_parents
NomenclaturalRank::Icn::GenusGroup.descendants.collect{|t| t.to_s} + NomenclaturalRank::Icn::SpeciesAndInfraspeciesGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Icn::GenusGroup,
NomenclaturalRank::Icn::SpeciesAndInfraspeciesGroup)
end
end
4 changes: 3 additions & 1 deletion app/models/nomenclatural_rank/iczn/family_group.rb
Expand Up @@ -5,7 +5,9 @@ def self.validate_name_format(taxon_name)
end

def self.valid_parents
NomenclaturalRank::Iczn::HigherClassificationGroup.descendants.collect{|t| t.to_s} + NomenclaturalRank::Iczn::FamilyGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Iczn::HigherClassificationGroup,
NomenclaturalRank::Iczn::FamilyGroup)
end

ENDINGS = %w{ini ina inae idae oidae odd ad oidea}
Expand Down
4 changes: 3 additions & 1 deletion app/models/nomenclatural_rank/iczn/genus_group.rb
Expand Up @@ -6,6 +6,8 @@ def self.validate_name_format(taxon_name)
end

def self.valid_parents
NomenclaturalRank::Iczn::FamilyGroup.descendants.collect{|t| t.to_s} + NomenclaturalRank::Iczn::GenusGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Iczn::FamilyGroup,
NomenclaturalRank::Iczn::GenusGroup)
end
end
Expand Up @@ -6,6 +6,7 @@ def self.validate_name_format(taxon_name)
end

def self.valid_parents
NomenclaturalRank::Iczn::HigherClassificationGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Iczn::HigherClassificationGroup)
end
end
4 changes: 3 additions & 1 deletion app/models/nomenclatural_rank/iczn/species_group.rb
Expand Up @@ -6,6 +6,8 @@ def self.validate_name_format(taxon_name)
end

def self.valid_parents
NomenclaturalRank::Iczn::SpeciesGroup.descendants.collect{|t| t.to_s} + NomenclaturalRank::Iczn::GenusGroup.descendants.collect{|t| t.to_s}
self.collect_descentants_to_s(
NomenclaturalRank::Iczn::SpeciesGroup,
NomenclaturalRank::Iczn::GenusGroup)
end
end

0 comments on commit 0fd0567

Please sign in to comment.