Class: Bridgetown::Resource::TaxonomyType

Inherits:
Object
  • Object
show all
Defined in:
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:



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

#keyString (readonly)

Returns the key used in front matter.

Returns:

  • (String)

    the key used in front matter



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

def key
  @key
end

#labelString (readonly)

Returns aka category, tag, region, etc.

Returns:

  • (String)

    aka category, tag, region, etc.



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

def label
  @label
end

#metadataHashWithDotAccess::Hash (readonly)

Returns any associated metadata.

Returns:



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

def 
  @metadata
end

#siteBridgetown::Site (readonly)

Returns:



7
8
9
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 7

def site
  @site
end

Instance Method Details

#as_jsonObject



47
48
49
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 47

def as_json(*)
  to_h
end

#inspectObject



34
35
36
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 34

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

#termsObject



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_jsonObject



51
52
53
# File 'lib/bridgetown-core/resource/taxonomy_type.rb', line 51

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

#to_liquidObject 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