Module: DecoratorDryer::Shortcuts::ClassMethods

Defined in:
lib/decorator_dryer/shortcuts.rb

Instance Method Summary collapse

Instance Method Details

#to_date_format(*attrs) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/decorator_dryer/shortcuts.rb', line 12

def to_date_format(*attrs)
  attrs.each do |attr|
    define_method(attr) do
      format_date object.send(attr)
    end
  end
end

#to_datetime_format(*attrs) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/decorator_dryer/shortcuts.rb', line 28

def to_datetime_format(*attrs)
  attrs.each do |attr|
    define_method(attr) do
      format_datetime object.send(attr)
    end
  end
end

#to_name(*attrs, suffix: "name") ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/decorator_dryer/shortcuts.rb', line 44

def to_name(*attrs, suffix: "name")
  attrs.each do |attr|
    method_name = "#{attr}_#{suffix}".to_sym

    define_method(method_name) do
      to_name object.send(attr)
    end
  end
end

#to_precision_number(*attrs, precision: 0) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/decorator_dryer/shortcuts.rb', line 36

def to_precision_number(*attrs, precision: 0)
  attrs.each do |attr|
    define_method(attr) do
      format_precision_number object.send(attr), precision
    end
  end
end

#to_time_format(*attrs) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/decorator_dryer/shortcuts.rb', line 20

def to_time_format(*attrs)
  attrs.each do |attr|
    define_method(attr) do
      format_time object.send(attr)
    end
  end
end