Class: WordpressClient::Term Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/wordpress_client/term.rb

Overview

This class is abstract.

Implement a subclass for the resource type.

Implementation for the abstract “term” in Wordpress.

See Also:

Direct Known Subclasses

Category, Tag

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name_html:, slug:) ⇒ Term

Returns a new instance of Term.



33
34
35
36
37
# File 'lib/wordpress_client/term.rb', line 33

def initialize(id:, name_html:, slug:)
  @id = id
  @name_html = name_html
  @slug = slug
end

Instance Attribute Details

#idFixnum (readonly)

Returns The ID of the resource in Wordpress.

Returns:

  • (Fixnum)

    The ID of the resource in Wordpress.



11
12
13
# File 'lib/wordpress_client/term.rb', line 11

def id
  @id
end

#name_htmlString (readonly)

Returns The name of the resource, HTML encoded.

Examples:

term.name_html #=> "Father & Daughter stuff"

Returns:

  • (String)

    The name of the resource, HTML encoded.



14
15
16
# File 'lib/wordpress_client/term.rb', line 14

def name_html
  @name_html
end

#slugString (readonly)

Returns The slug of the resource in Wordpress.

Returns:

  • (String)

    The slug of the resource in Wordpress.



19
20
21
# File 'lib/wordpress_client/term.rb', line 19

def slug
  @slug
end

Class Method Details

.parse(data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a data structure from a WP API response body into this term type.



25
26
27
28
29
30
31
# File 'lib/wordpress_client/term.rb', line 25

def self.parse(data)
  new(
    id: data.fetch("id"),
    name_html: data.fetch("name"),
    slug: data.fetch("slug"),
  )
end

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compares another instance. All attributes in this list must be equal for the instances to be equal:

  • id

  • name_html

  • slug

One must also not be a subclass of the other; they must be the exact same class.



48
49
50
51
52
53
54
55
56
57
# File 'lib/wordpress_client/term.rb', line 48

def ==(other)
  if other.is_a? Term
    other.class == self.class &&
      other.id == id &&
      other.name_html == name_html &&
      other.slug == slug
  else
    super
  end
end

#inspectObject

Shows a nice representation of the term type.



60
61
62
# File 'lib/wordpress_client/term.rb', line 60

def inspect
  "#<#{self.class} ##{id} #{name_html.inspect} (#{slug})>"
end