Class: Satis::InfoItem::Component

Inherits:
ApplicationComponent show all
Defined in:
app/components/satis/info_item/component.rb

Instance Attribute Summary collapse

Attributes inherited from ApplicationComponent

#original_view_context

Instance Method Summary collapse

Methods inherited from ApplicationComponent

add_helper, #component_name

Constructor Details

#initialize(name, *args, &block) ⇒ Component

Returns a new instance of Component.



8
9
10
11
12
13
14
15
16
# File 'app/components/satis/info_item/component.rb', line 8

def initialize(name, *args, &block)
  super
  @name = name
  @args = args
  @options = args.extract_options!
  @group = options[:group]
  @icon = options[:icon]
  @placeholder = options[:placeholder] || ''
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'app/components/satis/info_item/component.rb', line 6

def group
  @group
end

#iconObject (readonly)

Returns the value of attribute icon.



6
7
8
# File 'app/components/satis/info_item/component.rb', line 6

def icon
  @icon
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'app/components/satis/info_item/component.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'app/components/satis/info_item/component.rb', line 6

def options
  @options
end

Instance Method Details

#class_nameObject



38
39
40
# File 'app/components/satis/info_item/component.rb', line 38

def class_name
  "satis-info-item #{group}-info-item #{css_class_for_name}-info-item #{options[:class]}"
end

#string_contentsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/satis/info_item/component.rb', line 18

def string_contents
  @content = options[:content]
  @content = @content.call if @content.respond_to?(:call)

  case @content.presence
  when Time
    @content.strftime('%Y-%m-%d %H:%M')
  when ActiveRecord::Base
    @content.try(:human_name) || @content.try(:name) || "#{@content.class} ##{@content.id}"
  when Symbol
    @content.to_s.humanize
  when ActiveSupport::SafeBuffer
    @content
  when nil
    @placeholder
  else
    @content
  end
end