Module: Binda::FieldableAssociationHelpers::FieldableSvgHelpers
- Included in:
- Binda::FieldableAssociationHelpers
- Defined in:
- app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb
Instance Method Summary collapse
-
#bytes_to_megabytes(bytes) ⇒ Object
Convert bytes to megabites.
-
#get_svg_info(field_slug, info) ⇒ string, boolean
Get the object related to that field setting.
-
#get_svg_mime_type(field_slug) ⇒ string
Get svg type.
-
#get_svg_path(field_slug) ⇒ string
Get the svg path based on the size provided, default is Carrierwave default (usually the real size).
- #get_svg_size(field_slug) ⇒ Object
-
#get_svg_url(field_slug) ⇒ string
Get the svg url based on the size provided, default is Carrierwave default (usually the real size).
-
#has_svg(field_slug) ⇒ boolean
Check if the field has an attached audio.
Instance Method Details
#bytes_to_megabytes(bytes) ⇒ Object
Convert bytes to megabites
65 66 67 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb', line 65 def bytes_to_megabytes bytes (bytes.to_f / 1.megabyte).round(2) end |
#get_svg_info(field_slug, info) ⇒ string, boolean
Get the object related to that field setting
40 41 42 43 44 45 46 47 48 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb', line 40 def get_svg_info(field_slug, info) obj = self.svgs.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) } # Alternative query # obj = svg.where(field_setting_id: FieldSetting.get_id( field_slug ), fieldable_id: self.id, fieldable_type: self.class.to_s ).first raise ArgumentError, "There isn't any svg associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil? if obj.svg.present? obj.svg.send(info) end end |
#get_svg_mime_type(field_slug) ⇒ string
Get svg type
59 60 61 62 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb', line 59 def get_svg_mime_type(field_slug) obj = self.svgs.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) } return obj.content_type end |
#get_svg_path(field_slug) ⇒ string
Get the svg path based on the size provided,
default is Carrierwave default (usually the real size)
30 31 32 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb', line 30 def get_svg_path(field_slug) get_svg_info( field_slug, 'path' ) end |
#get_svg_size(field_slug) ⇒ Object
50 51 52 53 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb', line 50 def get_svg_size(field_slug) obj = self.svgs.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) } return bytes_to_megabytes(obj.file_size) end |
#get_svg_url(field_slug) ⇒ string
Get the svg url based on the size provided,
default is Carrierwave default (usually the real size)
21 22 23 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb', line 21 def get_svg_url(field_slug) get_svg_info( field_slug, 'url' ) end |
#has_svg(field_slug) ⇒ boolean
Check if the field has an attached audio
8 9 10 11 12 13 14 |
# File 'app/models/concerns/binda/fieldable_association_helpers/fieldable_svg_helpers.rb', line 8 def has_svg(field_slug) obj = self.svgs.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) } # Alternative query # obj = Image.where(field_setting_id: FieldSetting.get_id( field_slug ), fieldable_id: self.id, fieldable_type: self.class.to_s ).first raise ArgumentError, "There isn't any svg associated to the current slug (#{field_slug}) on instance (#{self.class.name} ##{self.id}).", caller if obj.nil? return obj.svg.present? end |