Class: HakumiComponents::Skeleton::AvatarConfig
- Inherits:
-
Object
- Object
- HakumiComponents::Skeleton::AvatarConfig
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/skeleton/avatar_config.rb
Constant Summary collapse
- Size =
T.type_alias { T.any(Symbol, Numeric) }
- ShapeInput =
T.type_alias { T.any(Symbol, String) }
- Input =
T.type_alias { T.any(T::Boolean, Types::HtmlAttributes, HakumiComponents::Skeleton::AvatarConfig) }
- SHAPES =
T.let(%i[circle square].freeze, T::Array[Symbol])
Instance Attribute Summary collapse
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(size: :default, shape: :circle) ⇒ AvatarConfig
constructor
A new instance of AvatarConfig.
Constructor Details
#initialize(size: :default, shape: :circle) ⇒ AvatarConfig
Returns a new instance of AvatarConfig.
15 16 17 18 19 |
# File 'app/components/hakumi_components/skeleton/avatar_config.rb', line 15 def initialize(size: :default, shape: :circle) @size = T.let(normalize_size(size), Size) @shape = T.let(normalize_shape(shape), Symbol) validate! end |
Instance Attribute Details
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
25 26 27 |
# File 'app/components/hakumi_components/skeleton/avatar_config.rb', line 25 def shape @shape end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
22 23 24 |
# File 'app/components/hakumi_components/skeleton/avatar_config.rb', line 22 def size @size end |
Class Method Details
.coerce(value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/components/hakumi_components/skeleton/avatar_config.rb', line 28 def self.coerce(value) return nil if value == false return new if value == true return value if value.is_a?(HakumiComponents::Skeleton::AvatarConfig) size = value[:size] shape = value[:shape] resolved_size = if size.is_a?(Symbol) || size.is_a?(Numeric) size elsif size.is_a?(String) size.to_sym else :default end resolved_shape = if shape.is_a?(Symbol) shape elsif shape.is_a?(String) shape.to_sym else :circle end new(size: resolved_size, shape: resolved_shape) end |