Class: Howdoc::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/howdoc/step.rb

Overview

One numbered instruction in a guide: what happened, optionally an illustration of it, and a flag for the steps that mark the reader's arrival on a new page.

What happened is kept as the action and the values it was recorded with, not as a finished sentence, because the same step is told in every language the guide is published in.

Defined Under Namespace

Classes: Narrated

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, action: nil, payload: {}, html: nil, screenshot: nil, arrival: false) ⇒ Step

Returns a new instance of Step.



24
25
26
27
28
29
30
31
# File 'lib/howdoc/step.rb', line 24

def initialize(number:, action: nil, payload: {}, html: nil, screenshot: nil, arrival: false)
  @number = number
  @action = action
  @payload = payload
  @html = html
  @screenshot = screenshot
  @arrival = arrival
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



21
22
23
# File 'lib/howdoc/step.rb', line 21

def action
  @action
end

#arrivalObject

Returns the value of attribute arrival.



22
23
24
# File 'lib/howdoc/step.rb', line 22

def arrival
  @arrival
end

#htmlObject

Returns the value of attribute html.



22
23
24
# File 'lib/howdoc/step.rb', line 22

def html
  @html
end

#numberObject (readonly)

Returns the value of attribute number.



21
22
23
# File 'lib/howdoc/step.rb', line 21

def number
  @number
end

#payloadObject (readonly)

Returns the value of attribute payload.



21
22
23
# File 'lib/howdoc/step.rb', line 21

def payload
  @payload
end

#screenshotObject

Returns the value of attribute screenshot.



22
23
24
# File 'lib/howdoc/step.rb', line 22

def screenshot
  @screenshot
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/howdoc/step.rb', line 33

def empty?
  html.nil? && action.nil? && screenshot.nil?
end

#html_in(locale) ⇒ Object

Markup a caller supplied stands in every language: it was written by the application, which knew what it was doing.



39
40
41
42
43
44
# File 'lib/howdoc/step.rb', line 39

def html_in(locale)
  return html unless html.nil?
  return nil if action.nil?

  Narrator.call(action, locale:, **payload)
end

#narrate(edition) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/howdoc/step.rb', line 46

def narrate(edition)
  Narrated.new(
    number:,
    html: html_in(edition.locale),
    screenshot: (edition.image_filename(number) if screenshot),
    arrival:
  )
end