Class: Cooklang::Builders::StepBuilder
- Inherits:
-
Object
- Object
- Cooklang::Builders::StepBuilder
- Defined in:
- lib/cooklang/builders/step_builder.rb
Instance Attribute Summary collapse
-
#cookware ⇒ Object
readonly
Access internal collections for compatibility.
-
#ingredients ⇒ Object
readonly
Access internal collections for compatibility.
-
#section_name ⇒ Object
readonly
Access internal collections for compatibility.
-
#segments ⇒ Object
readonly
Access internal collections for compatibility.
-
#timers ⇒ Object
readonly
Access internal collections for compatibility.
Instance Method Summary collapse
- #add_cookware(cookware) ⇒ Object
- #add_ingredient(ingredient) ⇒ Object
- #add_remaining_text(text) ⇒ Object
- #add_text(text) ⇒ Object
- #add_timer(timer) ⇒ Object
- #build ⇒ Object
-
#has_content? ⇒ Boolean
Check if the step has meaningful content.
-
#initialize ⇒ StepBuilder
constructor
A new instance of StepBuilder.
- #set_section_name(name) ⇒ Object
Constructor Details
#initialize ⇒ StepBuilder
Returns a new instance of StepBuilder.
6 7 8 9 10 11 12 |
# File 'lib/cooklang/builders/step_builder.rb', line 6 def initialize @segments = [] @ingredients = [] @cookware = [] @timers = [] @section_name = nil end |
Instance Attribute Details
#cookware ⇒ Object (readonly)
Access internal collections for compatibility
62 63 64 |
# File 'lib/cooklang/builders/step_builder.rb', line 62 def cookware @cookware end |
#ingredients ⇒ Object (readonly)
Access internal collections for compatibility
62 63 64 |
# File 'lib/cooklang/builders/step_builder.rb', line 62 def ingredients @ingredients end |
#section_name ⇒ Object (readonly)
Access internal collections for compatibility
62 63 64 |
# File 'lib/cooklang/builders/step_builder.rb', line 62 def section_name @section_name end |
#segments ⇒ Object (readonly)
Access internal collections for compatibility
62 63 64 |
# File 'lib/cooklang/builders/step_builder.rb', line 62 def segments @segments end |
#timers ⇒ Object (readonly)
Access internal collections for compatibility
62 63 64 |
# File 'lib/cooklang/builders/step_builder.rb', line 62 def timers @timers end |
Instance Method Details
#add_cookware(cookware) ⇒ Object
25 26 27 28 29 |
# File 'lib/cooklang/builders/step_builder.rb', line 25 def add_cookware(cookware) @cookware << cookware @segments << cookware self end |
#add_ingredient(ingredient) ⇒ Object
19 20 21 22 23 |
# File 'lib/cooklang/builders/step_builder.rb', line 19 def add_ingredient(ingredient) @ingredients << ingredient @segments << ingredient self end |
#add_remaining_text(text) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/cooklang/builders/step_builder.rb', line 37 def add_remaining_text(text) if text && !text.empty? @segments << text end self end |
#add_text(text) ⇒ Object
14 15 16 17 |
# File 'lib/cooklang/builders/step_builder.rb', line 14 def add_text(text) @segments << text self end |
#add_timer(timer) ⇒ Object
31 32 33 34 35 |
# File 'lib/cooklang/builders/step_builder.rb', line 31 def add_timer(timer) @timers << timer @segments << timer self end |
#build ⇒ Object
49 50 51 52 53 54 |
# File 'lib/cooklang/builders/step_builder.rb', line 49 def build # Clean up segments - remove trailing newlines cleaned_segments = remove_trailing_newlines(@segments.dup) Step.new(segments: cleaned_segments) end |
#has_content? ⇒ Boolean
Check if the step has meaningful content
57 58 59 |
# File 'lib/cooklang/builders/step_builder.rb', line 57 def has_content? @segments.any? { |segment| segment != "\n" && !(segment.is_a?(String) && segment.strip.empty?) } end |
#set_section_name(name) ⇒ Object
44 45 46 47 |
# File 'lib/cooklang/builders/step_builder.rb', line 44 def set_section_name(name) @section_name = name unless name&.empty? self end |