Class: Newsletter::Field::InlineAsset::Value

Inherits:
Object
  • Object
show all
Defined in:
app/models/newsletter/field/inline_asset.rb

Overview

create nicer accessors for use in design since this is more than one value, unlike other fields

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Value

Returns a new instance of Value.



71
72
73
74
75
76
# File 'app/models/newsletter/field/inline_asset.rb', line 71

def initialize(params)
  @url = params[:url]
  @text = params[:text]
  @asset = params[:asset]
  @asset_id = @asset.nil? ? nil : @asset.id
end

Instance Attribute Details

#assetObject

Returns the value of attribute asset.



55
56
57
# File 'app/models/newsletter/field/inline_asset.rb', line 55

def asset
  @asset
end

#asset_idObject

Returns the value of attribute asset_id.



55
56
57
# File 'app/models/newsletter/field/inline_asset.rb', line 55

def asset_id
  @asset_id
end

#textObject

Returns the value of attribute text.



55
56
57
# File 'app/models/newsletter/field/inline_asset.rb', line 55

def text
  @text
end

#urlObject

Returns the value of attribute url.



55
56
57
# File 'app/models/newsletter/field/inline_asset.rb', line 55

def url
  @url
end

Instance Method Details

#is_image?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
# File 'app/models/newsletter/field/inline_asset.rb', line 56

def is_image?
  if asset.present?
    asset.is_image?
  else
    is_image_by_extension?
  end
end

#is_image_by_extension?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
# File 'app/models/newsletter/field/inline_asset.rb', line 64

def is_image_by_extension?
  extension = File.extname(url).gsub(/^\./,'')
  [ 'bmp', 'cod', 'gif', 'ief', 'jpe', 'jpeg', 'jpg', 'png',
    'jfif', 'svg', 'tif', 'tiff'
  ].include?(extension.downcase)
end