Class: RubyUIAdmin::Cards::BaseCard
- Inherits:
-
Object
- Object
- RubyUIAdmin::Cards::BaseCard
show all
- Defined in:
- lib/ruby_ui_admin/cards/base_card.rb
Overview
Base class for dashboard cards. Subclasses override query to compute their
value/data. Mirrors the Filters pattern: base types live here and host cards
(RubyUIAdmin::Cards::*) inherit them.
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**options) ⇒ BaseCard
Returns a new instance of BaseCard.
35
36
37
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 35
def initialize(**options)
@options = options
end
|
Class Attribute Details
.label ⇒ Object
12
13
14
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 12
def label
(defined?(@label) && @label) || to_s.demodulize.titleize
end
|
.width ⇒ Object
16
17
18
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 16
def width
(defined?(@width) && @width) || 1
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
33
34
35
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 33
def options
@options
end
|
Class Method Details
.card_type ⇒ Object
Inherited down the chain (subclasses of MetricCard are :metric, etc.).
21
22
23
24
25
26
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 21
def card_type
return @card_type if defined?(@card_type) && @card_type
return superclass.card_type if superclass.respond_to?(:card_type)
nil
end
|
.register_type(type) ⇒ Object
28
29
30
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 28
def register_type(type)
@card_type = type.to_sym
end
|
Instance Method Details
#card_id ⇒ Object
51
52
53
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 51
def card_id
self.class.to_s.demodulize.underscore
end
|
#label ⇒ Object
39
40
41
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 39
def label
self.class.label
end
|
#query ⇒ Object
Override in subclasses to compute the card's value/data.
56
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 56
def query; end
|
#type ⇒ Object
47
48
49
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 47
def type
self.class.card_type
end
|
#width ⇒ Object
43
44
45
|
# File 'lib/ruby_ui_admin/cards/base_card.rb', line 43
def width
self.class.width
end
|