Class: Ace::Bundle::Models::BundleData
- Inherits:
-
Object
- Object
- Ace::Bundle::Models::BundleData
- Defined in:
- lib/ace/bundle/models/bundle_data.rb
Overview
Data model for bundle information
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#content ⇒ Object
Returns the value of attribute content.
-
#files ⇒ Object
Returns the value of attribute files.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#preset_name ⇒ Object
Returns the value of attribute preset_name.
-
#sections ⇒ Object
Returns the value of attribute sections.
Instance Method Summary collapse
- #add_file(path, content) ⇒ Object
-
#add_section(name, section_data) ⇒ Object
Section-related methods.
- #clear_sections ⇒ Object
- #file_count ⇒ Object
- #get_section(name) ⇒ Object
- #has_sections? ⇒ Boolean
-
#initialize(preset_name: nil, files: nil, metadata: nil, content: "", commands: nil, sections: nil) ⇒ BundleData
constructor
A new instance of BundleData.
- #section_count ⇒ Object
- #section_names ⇒ Object
- #sorted_sections ⇒ Object
- #to_h ⇒ Object
- #total_size ⇒ Object
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
#commands ⇒ Object
Returns the value of attribute commands.
8 9 10 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 8 def commands @commands end |
#content ⇒ Object
Returns the value of attribute content.
8 9 10 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 8 def content @content end |
#files ⇒ Object
Returns the value of attribute files.
8 9 10 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 8 def files @files end |
#metadata ⇒ Object
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 8 def @metadata end |
#preset_name ⇒ Object
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 |
#sections ⇒ Object
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_sections ⇒ Object
69 70 71 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 69 def clear_sections @sections.clear end |
#file_count ⇒ Object
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
51 52 53 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 51 def has_sections? !@sections.empty? end |
#section_count ⇒ Object
55 56 57 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 55 def section_count @sections.size end |
#section_names ⇒ Object
65 66 67 |
# File 'lib/ace/bundle/models/bundle_data.rb', line 65 def section_names @sections.keys end |
#sorted_sections ⇒ Object
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_h ⇒ Object
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_size ⇒ Object
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 |