Skip to content

Commit

Permalink
Improve link object processing
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Eugene committed Apr 6, 2024
1 parent 1dfba85 commit 35fffd5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/vk/vk_informer_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class Link < Attachment
def initialize(domain, node)
super

@text = "[#{node[:link][:title]}](#{node[:link][:url]})"
@preview = get_image(node) if node[:link].key? :image_src
title = (node[:link][:title] || '').empty? ? node[:link][:url] : node[:link][:title]

@text = "[#{title}](#{node[:link][:url]})"
@preview = get_image(node) if node[:link].key? :photo
end

def to_hash
Expand All @@ -37,7 +39,7 @@ def preview?
end

def get_image(node)
node[:link][node[:link].key?(:image_big) ? :image_big : :image_src]
node[:link][:photo]
end

def to_hash_text
Expand Down
3 changes: 1 addition & 2 deletions spec/fixtures/vk_informer_attachment/link/hash.w_prev.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"title": "sometext",
"description": "link description",
"target": "internal",
"image_src": "http://example.com/image.small.jpg",
"image_big": "http://example.com/image.jpg"
"photo": "http://example.com/image.jpg"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"title": "sometext",
"description": "link description",
"target": "internal",
"image_src": "http://example.com/image.small.jpg"
"photo": "http://example.com/image.small.jpg"
}
}

0 comments on commit 35fffd5

Please sign in to comment.