Class: Ace::Bundle::Models::BundleData

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/bundle/models/bundle_data.rb

Overview

Data model for bundle information

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(preset_name: nil, files: nil, metadata: nil, content: "", commands: nil, sections: nil) ⇒ BundleData

Returns a new instance of BundleData.



10
11
12
13
14
15
16
17
# File 'lib/ace/bundle/models/bundle_data.rb', line 10

def initialize(preset_name: nil, files: nil, metadata: nil, content: "", commands: nil, sections: nil)
  @preset_name = preset_name
  @files = files || []
  @metadata =  || {}
  @content = content
  @commands = commands || []
  @sections = sections || {}
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



8
9
10
# File 'lib/ace/bundle/models/bundle_data.rb', line 8

def commands
  @commands
end

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/ace/bundle/models/bundle_data.rb', line 8

def content
  @content
end

#filesObject

Returns the value of attribute files.



8
9
10
# File 'lib/ace/bundle/models/bundle_data.rb', line 8

def files
  @files
end

#metadataObject

Returns the value of attribute metadata.



8
9
10
# File 'lib/ace/bundle/models/bundle_data.rb', line 8

def 
  @metadata
end

#preset_nameObject

Returns the value of attribute preset_name.



8
9
10
# File 'lib/ace/bundle/models/bundle_data.rb', line 8

def preset_name
  @preset_name
end

#sectionsObject

Returns the value of attribute sections.



8
9
10
# File 'lib/ace/bundle/models/bundle_data.rb', line 8

def sections
  @sections
end

Instance Method Details

#add_file(path, content) ⇒ Object



30
31
32
# File 'lib/ace/bundle/models/bundle_data.rb', line 30

def add_file(path, content)
  @files << {path: path, content: content}
end

#add_section(name, section_data) ⇒ Object

Section-related methods



43
44
45
# File 'lib/ace/bundle/models/bundle_data.rb', line 43

def add_section(name, section_data)
  @sections[name] = section_data
end

#clear_sectionsObject



69
70
71
# File 'lib/ace/bundle/models/bundle_data.rb', line 69

def clear_sections
  @sections.clear
end

#file_countObject



34
35
36
# File 'lib/ace/bundle/models/bundle_data.rb', line 34

def file_count
  @files.size
end

#get_section(name) ⇒ Object



47
48
49
# File 'lib/ace/bundle/models/bundle_data.rb', line 47

def get_section(name)
  @sections[name]
end

#has_sections?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ace/bundle/models/bundle_data.rb', line 51

def has_sections?
  !@sections.empty?
end

#section_countObject



55
56
57
# File 'lib/ace/bundle/models/bundle_data.rb', line 55

def section_count
  @sections.size
end

#section_namesObject



65
66
67
# File 'lib/ace/bundle/models/bundle_data.rb', line 65

def section_names
  @sections.keys
end

#sorted_sectionsObject



59
60
61
62
63
# File 'lib/ace/bundle/models/bundle_data.rb', line 59

def sorted_sections
  # In Ruby 3.2+, hash insertion order is preserved
  # This returns sections in the order they appear in the YAML file
  @sections.to_a
end

#to_hObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/ace/bundle/models/bundle_data.rb', line 19

def to_h
  {
    preset_name: preset_name,
    files: files,
    metadata: ,
    content: content,
    commands: commands,
    sections: sections
  }
end

#total_sizeObject



38
39
40
# File 'lib/ace/bundle/models/bundle_data.rb', line 38

def total_size
  @files.sum { |f| f[:content].to_s.bytesize }
end