Class: Bridgetown::Resource::TaxonomyType

Inherits:
Object
  • Object
show all
Defined in:
bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site:, label:, key:, metadata:) ⇒ TaxonomyType

Returns a new instance of TaxonomyType.

Parameters:



23
24
25
26
27
28
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 23

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.

Returns:

  • (String) —

    the key used in front matter



15
16
17
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 15

def key
  @key
end

#label ⇒ String (readonly)

Returns aka category, tag, region, etc.

Returns:

  • (String) —

    aka category, tag, region, etc.



12
13
14
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 12

def label
  @label
end

#metadata ⇒ HashWithDotAccess::Hash (readonly)

Returns any associated metadata.

Returns:



18
19
20
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 18

def 
  @metadata
end

#site ⇒ Bridgetown::Site (readonly)

Returns:



9
10
11
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 9

def site
  @site
end

Instance Method Details

#as_json ⇒ Object



49
50
51
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 49

def as_json(*)
  to_h
end

#inspect ⇒ Object



36
37
38
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 36

def inspect
  "#<#{self.class} label=#{label}>"
end

#terms ⇒ Object



30
31
32
33
34
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 30

def terms
  site.resources.map do |resource|
    resource.taxonomies[label].terms
  end.flatten.group_by(&:label).as_dots
end

#to_json ⇒ Object



53
54
55
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 53

def to_json(...)
  as_json(...).to_json(...)
end

#to_liquid ⇒ Object Also known as: to_h



40
41
42
43
44
45
46
# File 'bridgetown-core/lib/bridgetown-core/resource/taxonomy_type.rb', line 40

def to_liquid
  {
    "label"    => label,
    "key"      => key,
    "metadata" => ,
  }
end