Class: GsImgFetcher::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/gs_img_fetcher/entry.rb

Constant Summary collapse

ALLOWED_EXTENSIONS =
%w[jpeg jpg png gif svg].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Entry

Returns a new instance of Entry.



9
10
11
# File 'lib/gs_img_fetcher/entry.rb', line 9

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/gs_img_fetcher/entry.rb', line 7

def url
  @url
end

Instance Method Details

#extensionObject



13
14
15
# File 'lib/gs_img_fetcher/entry.rb', line 13

def extension
  @extension ||= ([filename.split('.').last&.downcase] & ALLOWED_EXTENSIONS).first
end

#valid?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/gs_img_fetcher/entry.rb', line 17

def valid?
  [filename, extension].all?(&:present?)
end