Class: WordpressClient::Media
- Inherits:
-
Object
- Object
- WordpressClient::Media
- Defined in:
- lib/wordpress_client/media.rb
Overview
Represents a media record in Wordpress.
Instance Attribute Summary collapse
-
#alt_text ⇒ Object
Returns the value of attribute alt_text.
-
#date ⇒ Time?
The date of the media, in UTC if available.
-
#description ⇒ Object
Returns the value of attribute description.
-
#guid ⇒ String
(also: #source_url)
Returns the permalink/GUID – or
source_url
– of the media. -
#id ⇒ Object
Returns the value of attribute id.
-
#link ⇒ Object
Returns the value of attribute link.
-
#media_details ⇒ Hash<String,Object>
Returns the media details if available.
-
#media_type ⇒ String
The type of the media.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#title_html ⇒ String
The title of the media, HTML escaped.
-
#updated_at ⇒ Time?
The modification date of the media, in UTC if available.
Class Method Summary collapse
- .parse(data) ⇒ Object private
Instance Method Summary collapse
-
#as_image ⇒ Object
Returns the same
Media
instance if it is an image, elsenil
. -
#initialize(id: nil, slug: nil, media_type: nil, title_html: nil, alt_text: nil, description: nil, date: nil, updated_at: nil, guid: nil, link: nil, media_details: {}) ⇒ Media
constructor
Creates a new instance, populating the fields with the passed values.
Constructor Details
#initialize(id: nil, slug: nil, media_type: nil, title_html: nil, alt_text: nil, description: nil, date: nil, updated_at: nil, guid: nil, link: nil, media_details: {}) ⇒ Media
Creates a new instance, populating the fields with the passed values.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/wordpress_client/media.rb', line 50 def initialize( id: nil, slug: nil, media_type: nil, title_html: nil, alt_text: nil, description: nil, date: nil, updated_at: nil, guid: nil, link: nil, media_details: {} ) @id = id @slug = slug @media_type = media_type @title_html = title_html @date = date @updated_at = updated_at @alt_text = alt_text @description = description @guid = guid @link = link @media_details = media_details end |
Instance Attribute Details
#alt_text ⇒ Object
Returns the value of attribute alt_text.
4 5 6 |
# File 'lib/wordpress_client/media.rb', line 4 def alt_text @alt_text end |
#date ⇒ Time?
Returns the date of the media, in UTC if available.
20 21 22 |
# File 'lib/wordpress_client/media.rb', line 20 def date @date end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/wordpress_client/media.rb', line 4 def description @description end |
#guid ⇒ String Also known as: source_url
Returns the permalink/GUID – or source_url
– of the media.
Media that are embedded in posts have a source_url
attribute and no guid
, and stand-alone media has a guid
but no source_url
. They are both backed by the same data, so this method handles both cases, and is aliased to both names.
26 27 28 |
# File 'lib/wordpress_client/media.rb', line 26 def guid @guid end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/wordpress_client/media.rb', line 4 def id @id end |
#link ⇒ Object
Returns the value of attribute link.
4 5 6 |
# File 'lib/wordpress_client/media.rb', line 4 def link @link end |
#media_details ⇒ Hash<String,Object>
Returns the media details if available.
Media details cannot be documented here. It’s up to you to handle this generic “payload” attribute the best way you can.
36 37 38 |
# File 'lib/wordpress_client/media.rb', line 36 def media_details @media_details end |
#media_type ⇒ String
Returns the type of the media.
10 11 12 |
# File 'lib/wordpress_client/media.rb', line 10 def media_type @media_type end |
#slug ⇒ Object
Returns the value of attribute slug.
4 5 6 |
# File 'lib/wordpress_client/media.rb', line 4 def slug @slug end |
#title_html ⇒ String
Returns the title of the media, HTML escaped.
15 16 17 |
# File 'lib/wordpress_client/media.rb', line 15 def title_html @title_html end |
#updated_at ⇒ Time?
Returns the modification date of the media, in UTC if available.
23 24 25 |
# File 'lib/wordpress_client/media.rb', line 23 def updated_at @updated_at 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.
45 46 47 |
# File 'lib/wordpress_client/media.rb', line 45 def self.parse(data) MediaParser.parse(data) end |
Instance Method Details
#as_image ⇒ Object
Returns the same Media
instance if it is an image, else nil
.
79 80 81 82 83 |
# File 'lib/wordpress_client/media.rb', line 79 def as_image if media_type == "image" self end end |