Class: Refinery::WordPress::Attachment
- Inherits:
-
Object
- Object
- Refinery::WordPress::Attachment
- Defined in:
- lib/wordpress/attachment.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#refinery_image ⇒ Object
readonly
Returns the value of attribute refinery_image.
-
#refinery_resource ⇒ Object
readonly
Returns the value of attribute refinery_resource.
Instance Method Summary collapse
- #description ⇒ Object
- #file_name ⇒ Object
- #image? ⇒ Boolean
-
#initialize(node) ⇒ Attachment
constructor
A new instance of Attachment.
- #post_date ⇒ Object
- #replace_url ⇒ Object
- #title ⇒ Object
- #to_refinery ⇒ Object
- #url ⇒ Object
- #url_pattern ⇒ Object
Constructor Details
#initialize(node) ⇒ Attachment
Returns a new instance of Attachment.
8 9 10 |
# File 'lib/wordpress/attachment.rb', line 8 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
4 5 6 |
# File 'lib/wordpress/attachment.rb', line 4 def node @node end |
#refinery_image ⇒ Object (readonly)
Returns the value of attribute refinery_image.
5 6 7 |
# File 'lib/wordpress/attachment.rb', line 5 def refinery_image @refinery_image end |
#refinery_resource ⇒ Object (readonly)
Returns the value of attribute refinery_resource.
6 7 8 |
# File 'lib/wordpress/attachment.rb', line 6 def refinery_resource @refinery_resource end |
Instance Method Details
#description ⇒ Object
16 17 18 |
# File 'lib/wordpress/attachment.rb', line 16 def description node.xpath("description").text end |
#file_name ⇒ Object
20 21 22 |
# File 'lib/wordpress/attachment.rb', line 20 def file_name url.split('/').last end |
#image? ⇒ Boolean
40 41 42 |
# File 'lib/wordpress/attachment.rb', line 40 def image? url.match /\.(png|jpg|jpeg|gif)$/ end |
#post_date ⇒ Object
24 25 26 |
# File 'lib/wordpress/attachment.rb', line 24 def post_date DateTime.parse node.xpath("wp:post_date").text end |
#replace_url ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/wordpress/attachment.rb', line 52 def replace_url if image? replace_image_url else replace_resource_url end end |
#title ⇒ Object
12 13 14 |
# File 'lib/wordpress/attachment.rb', line 12 def title node.xpath("title").text end |
#to_refinery ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/wordpress/attachment.rb', line 44 def to_refinery if image? to_image else to_resource end end |
#url ⇒ Object
28 29 30 |
# File 'lib/wordpress/attachment.rb', line 28 def url node.xpath("wp:attachment_url").text end |
#url_pattern ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/wordpress/attachment.rb', line 32 def url_pattern url_parts = url.split('.') extension = url_parts.pop url_without_extension = url_parts.join('.') /#{url_without_extension}(-\d+x\d+)?\.#{extension}/ end |