Class: Mexico::FileSystem::Corpus
- Inherits:
-
Object
- Object
- Mexico::FileSystem::Corpus
- Includes:
- Core::CorpusCore, Poseidon, ROXML
- Defined in:
- lib/mexico/file_system/corpus.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
Class Method Summary collapse
-
.open(path, opts = {}) ⇒ Mexico::FileSystem::Corpus
Opens the corpus folder and its manifest file at the given path.
Instance Method Summary collapse
-
#complete_file_size ⇒ Integer
Returns the disk usage in bytes for the whole corpus.
-
#create_design(opts = {}) ⇒ Object
Creates a new design object and binds it to this corpus object.
-
#initialize(opts = {}) ⇒ Corpus
constructor
Creates a new corpus object.
-
#save_xml ⇒ void
Saves the current data structure to the current file handle.
Methods included from Core::CorpusCore
Constructor Details
#initialize(opts = {}) ⇒ Corpus
Creates a new corpus object
91 92 93 94 95 96 97 98 |
# File 'lib/mexico/file_system/corpus.rb', line 91 def initialize(path, opts={}) init_folder(path, opts) @base_path = File.(path) @corpus_file_name = File.join(@base_path, "Corpus.xml") f = File.open(@corpus_file_name, 'r') @xml_doc = ::Nokogiri::XML(f) f.close end |
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
33 34 35 |
# File 'lib/mexico/file_system/corpus.rb', line 33 def base_path @base_path end |
Class Method Details
.open(path, opts = {}) ⇒ Mexico::FileSystem::Corpus
Opens the corpus folder and its manifest file at the given path.
82 83 84 85 86 |
# File 'lib/mexico/file_system/corpus.rb', line 82 def self.open(path, opts={}) xml = File.open(File.join(path,'Corpus.xml'),'rb') { |f| f.read } c = Mexico::FileSystem::Corpus.from_xml(xml, opts.merge({:path=>path})) return c end |
Instance Method Details
#complete_file_size ⇒ Integer
Returns the disk usage in bytes for the whole corpus.
137 138 139 |
# File 'lib/mexico/file_system/corpus.rb', line 137 def complete_file_size resources.collect{ |r| r.complete_file_size }.inject(:+) end |
#create_design(opts = {}) ⇒ Object
Creates a new design object and binds it to this corpus object.
129 130 131 132 133 |
# File 'lib/mexico/file_system/corpus.rb', line 129 def create_design(opts={}) d = ::Mexico::FileSystem::Design.new(opts) d.bind_to_corpus(self) d end |
#save_xml ⇒ void
This method returns an undefined value.
Saves the current data structure to the current file handle.
116 117 118 119 120 121 122 123 |
# File 'lib/mexico/file_system/corpus.rb', line 116 def save_xml doc = Nokogiri::XML::Document.new doc.root = @corpus.to_xml open(File.join(@base_path, "Corpus.OUT.xml"), 'w') do |file| file << doc.serialize end # File.open(@corpus_file, 'w') {|f| f.write(doc.to_xml) } end |