Class: HakumiComponents::Tour::Step

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/components/hakumi_components/tour/step.rb

Constant Summary collapse

InputValue =
T.type_alias { T.nilable(Types::StringOrSymbol) }
InputHash =
T.type_alias { T.any(T::Hash[Symbol, InputValue], T::Hash[String, InputValue]) }
Source =
T.type_alias { T.any(Step, InputHash) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, body:, placement:, target: nil) ⇒ Step

Returns a new instance of Step.



21
22
23
24
25
26
# File 'app/components/hakumi_components/tour/step.rb', line 21

def initialize(title:, body:, placement:, target: nil)
  @title = title
  @body = body
  @target = target
  @placement = placement
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



32
33
34
# File 'app/components/hakumi_components/tour/step.rb', line 32

def body
  @body
end

#placementObject (readonly)

Returns the value of attribute placement.



38
39
40
# File 'app/components/hakumi_components/tour/step.rb', line 38

def placement
  @placement
end

#targetObject (readonly)

Returns the value of attribute target.



35
36
37
# File 'app/components/hakumi_components/tour/step.rb', line 35

def target
  @target
end

#titleObject (readonly)

Returns the value of attribute title.



29
30
31
# File 'app/components/hakumi_components/tour/step.rb', line 29

def title
  @title
end

Class Method Details

.from_input(step, default_placement:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/components/hakumi_components/tour/step.rb', line 41

def self.from_input(step, default_placement:)
  return step if step.is_a?(Step)

  title = read_input(step, :title).to_s
  body = read_input(step, :body, :description).to_s
  target = read_input(step, :target)&.to_s
  placement = (read_input(step, :placement) || default_placement).to_s.to_sym

  Step.new(
    title: title,
    body: body,
    placement: placement,
    target: target
  )
end

Instance Method Details

#to_hObject



58
59
60
61
62
63
64
65
# File 'app/components/hakumi_components/tour/step.rb', line 58

def to_h
  {
    title: @title,
    body: @body,
    target: @target,
    placement: @placement.to_s.tr("_", "-")
  }
end