Class: Bridgetown::Resource::TaxonomyType
- Inherits:
-
Object
- Object
- Bridgetown::Resource::TaxonomyType
- Defined in:
- lib/bridgetown-core/resource/taxonomy_type.rb
Instance Attribute Summary collapse
-
#key ⇒ String
readonly
The key used in front matter.
-
#label ⇒ String
readonly
Aka
category
,tag
,region
, etc. -
#metadata ⇒ HashWithDotAccess::Hash
readonly
Any associated metadata.
- #site ⇒ Bridgetown::Site readonly
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(site:, label:, key:, metadata:) ⇒ TaxonomyType
constructor
A new instance of TaxonomyType.
- #inspect ⇒ Object
- #terms ⇒ Object
- #to_json ⇒ Object
- #to_liquid ⇒ Object (also: #to_h)
Constructor Details
#initialize(site:, label:, key:, metadata:) ⇒ TaxonomyType
Returns a new instance of TaxonomyType.
21 22 23 24 25 26 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 21 def initialize(site:, label:, key:, metadata:) @site = site @label = label @key = key @metadata = end |
Instance Attribute Details
#key ⇒ String (readonly)
Returns the key used in front matter.
13 14 15 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 13 def key @key end |
#label ⇒ String (readonly)
Returns aka category
, tag
, region
, etc.
10 11 12 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 10 def label @label end |
#metadata ⇒ HashWithDotAccess::Hash (readonly)
Returns any associated metadata.
16 17 18 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 16 def @metadata end |
#site ⇒ Bridgetown::Site (readonly)
7 8 9 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 7 def site @site end |
Instance Method Details
#as_json ⇒ Object
47 48 49 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 47 def as_json(*) to_h end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 34 def inspect "#<#{self.class} label=#{label}>" end |
#terms ⇒ Object
28 29 30 31 32 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 28 def terms site.resources.map do |resource| resource.taxonomies[label].terms end.flatten.group_by(&:label).with_dot_access end |
#to_json ⇒ Object
51 52 53 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 51 def to_json(...) as_json(...).to_json(...) end |
#to_liquid ⇒ Object Also known as: to_h
38 39 40 41 42 43 44 |
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 38 def to_liquid { "label" => label, "key" => key, "metadata" => , } end |