Skip to content

Commit

Permalink
Simplify the code around parent taxons
Browse files Browse the repository at this point in the history
Move everything to the parent_taxon method, and use dig to pull out
the first parent taxon.
  • Loading branch information
Christopher Baines committed May 3, 2018
1 parent a3f82cb commit 078a4c7
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/govuk_publishing_components/app_helpers/taxon_breadcrumbs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,10 @@ def initialize(content_item)
end

def parent_taxon
parent_taxons.first
end
@_parent_taxon ||= begin
parent_content_item = content_item.dig("links", "parent_taxons", 0)

def parent_taxons
@_parent_taxons ||= begin
content_item.dig("links", "parent_taxons")
.to_a
.map { |taxon| ContentItem.new(taxon) }
ContentItem.new(parent_content_item) unless parent_content_item.nil?
end
end

Expand Down

0 comments on commit 078a4c7

Please sign in to comment.