Class: TinyAdmin::Support

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_admin/support.rb

Class Method Summary collapse

Class Method Details

.call(value, options: []) ⇒ Object



10
11
12
# File 'lib/tiny_admin/support.rb', line 10

def call(value, options: [])
  options.inject(value) { |result, message| result&.send(message) } if value && options&.any?
end

.downcase(value, options: []) ⇒ Object



14
15
16
# File 'lib/tiny_admin/support.rb', line 14

def downcase(value, options: [])
  value&.downcase
end

.format(value, options: []) ⇒ Object



18
19
20
# File 'lib/tiny_admin/support.rb', line 18

def format(value, options: [])
  Kernel.format(options.first, value) if value && options&.any?
end

.label_for(value, options: []) ⇒ Object



22
23
24
# File 'lib/tiny_admin/support.rb', line 22

def label_for(value, options: [])
  value
end

.multiline(array, options: []) ⇒ Object



40
41
42
43
44
# File 'lib/tiny_admin/support.rb', line 40

def multiline(array, options: [])
  return unless array.is_a?(Array)

  raw_html(array.join("<br/>"))
end

.raw_html(value) ⇒ Object



6
7
8
# File 'lib/tiny_admin/support.rb', line 6

def raw_html(value)
  TinyAdmin::RawHtml.new(value)
end

.round(value, options: []) ⇒ Object



26
27
28
# File 'lib/tiny_admin/support.rb', line 26

def round(value, options: [])
  value&.round(options&.first&.to_i || 2)
end

.strftime(value, options: []) ⇒ Object



30
31
32
# File 'lib/tiny_admin/support.rb', line 30

def strftime(value, options: [])
  value&.strftime(options&.first || "%Y-%m-%d %H:%M")
end

.to_date(value, options: []) ⇒ Object



34
35
36
37
38
# File 'lib/tiny_admin/support.rb', line 34

def to_date(value, options: [])
  value&.to_date&.to_s
rescue NoMethodError, ArgumentError
  value&.to_s
end

.upcase(value, options: []) ⇒ Object



46
47
48
# File 'lib/tiny_admin/support.rb', line 46

def upcase(value, options: [])
  value&.upcase
end