Class: WordpressClient::Term Abstract
- Inherits:
-
Object
- Object
- WordpressClient::Term
- Defined in:
- lib/wordpress_client/term.rb
Overview
Implement a subclass for the resource type.
Implementation for the abstract “term” in Wordpress.
Instance Attribute Summary collapse
-
#id ⇒ Fixnum
readonly
The ID of the resource in Wordpress.
-
#name_html ⇒ String
readonly
The name of the resource, HTML encoded.
-
#slug ⇒ String
readonly
The slug of the resource in Wordpress.
Class Method Summary collapse
-
.parse(data) ⇒ Object
private
Parses a data structure from a WP API response body into this term type.
Instance Method Summary collapse
-
#==(other) ⇒ Object
private
Compares another instance.
-
#initialize(id:, name_html:, slug:) ⇒ Term
constructor
A new instance of Term.
-
#inspect ⇒ Object
Shows a nice representation of the term type.
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
#id ⇒ Fixnum (readonly)
Returns The ID of the resource in Wordpress.
11 12 13 |
# File 'lib/wordpress_client/term.rb', line 11 def id @id end |
#name_html ⇒ String (readonly)
Returns The name of the resource, HTML encoded.
14 15 16 |
# File 'lib/wordpress_client/term.rb', line 14 def name_html @name_html end |
#slug ⇒ String (readonly)
Returns 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 |
#inspect ⇒ Object
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 |