docbrown/app/labor/generated_image.rb
rhymes 6553f08d94 Rubocop cleanups (#1415)
* Update rubocop-todo.yml with new violations

* Fix Layout/EmptyLine* rules

* Fix Layout/Indentation* rules

* Fix remaining Layout/* rules

* Fix Lint/DuplicateMethods by removing unused accessor

* Fix Lint/IneffectiveAccessModifier

* Fix Lint/MissingCopEnableDirective

* Re-run rubocop auto gen config

* Fix Layout/RescueEnsureAlignment

* Fix Naming/* rules

* Fix some RSpec/* rules

* Fix typos

* Fix RSpec/LetBeforeExamples

* Series should only be an attr_writer, not an attr_accessor

* Fix RSpec/InstanceVariable

* Fix RSpec/InstanceVariable

* Fix RSpec/RepeatedDescription and RSpec/RepeatedExample

* Fix Style/ClassAndModuleChildren

* Fix Style/ConditionalAssignment

* Fix some Style/* rules

* Trigger Travis CI build because failing tests are not failing locally

* Revert "Fix Style/ClassAndModuleChildren"

This reverts commit 1686801d8a1516ba1894f79e24401a20dea65f99.
2019-01-02 11:20:02 -05:00

38 lines
1.2 KiB
Ruby

class GeneratedImage
include CloudinaryHelper
attr_reader :resource
def initialize(resource)
@resource = resource
end
def social_image
if resource.class.name.include?("Article")
article_image
elsif resource.class.name == "User"
cloudinary_generated_url "/user/#{resource.id}?bust=#{resource.profile_image_url}"
elsif resource.class.name == "Organization"
cloudinary_generated_url "/organization/#{resource.id}?bust=#{resource.profile_image_url}"
elsif resource.class.name.include?("Tag")
cloudinary_generated_url "/tag/#{@resource.id}?bust=#{@resource.pretty_name}"
end
end
def article_image
return resource.social_image if resource.social_image.present?
return resource.main_image if resource.main_image.present?
return resource.video_thumbnail_url if resource.video_thumbnail_url.present?
cloudinary_generated_url "/article/#{resource.id}?bust=#{resource.comments_count}-#{resource.title}-#{resource.published}"
end
def cloudinary_generated_url(path)
cl_image_path("https://dev.to/social_previews#{path}",
gravity: "north",
height: 400,
width: 800,
crop: "fill",
sign_url: true,
type: "url2png")
end
end