Class: Refinery::WordPress::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/wordpress/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/wordpress/attachment.rb', line 4

def node
  @node
end

#refinery_imageObject (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_resourceObject (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

#descriptionObject



16
17
18
# File 'lib/wordpress/attachment.rb', line 16

def description
  node.xpath("description").text
end

#file_nameObject



20
21
22
# File 'lib/wordpress/attachment.rb', line 20

def file_name
  url.split('/').last
end

#image?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/wordpress/attachment.rb', line 40

def image?
  url.match /\.(png|jpg|jpeg|gif)$/ 
end

#post_dateObject



24
25
26
# File 'lib/wordpress/attachment.rb', line 24

def 
  DateTime.parse node.xpath("wp:post_date").text
end

#replace_urlObject



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

#titleObject



12
13
14
# File 'lib/wordpress/attachment.rb', line 12

def title
  node.xpath("title").text
end

#to_refineryObject



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

#urlObject



28
29
30
# File 'lib/wordpress/attachment.rb', line 28

def url
  node.xpath("wp:attachment_url").text
end

#url_patternObject



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