Class: Mexico::FileSystem::Corpus

Inherits:
Object
  • Object
show all
Includes:
Core::CorpusCore, Poseidon, ROXML
Defined in:
lib/mexico/file_system/corpus.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::CorpusCore

#core_included?

Constructor Details

#initialize(opts = {}) ⇒ Corpus

Creates a new corpus object

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :path (String)

    The path where to create the new corpus. Required.

  • :identifier (String)

    The identifier for the new corpus. Required.

  • :name (String)

    The name for the new corpus.

  • :description (String)

    A description for the new corpus. Required.



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.expand_path(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_pathObject

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.

Parameters:

  • path (String)

    the path where the corpus is

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :identifier (String)

    The identifier that will be given if a new corpus is created

Returns:



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_sizeInteger

Returns the disk usage in bytes for the whole corpus.

Returns:

  • (Integer)

    the number of bytes used by files of this 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.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :identifier (String)

    The identifier of the new design (required).

  • :name (String)

    The name of the new design. (required).

  • :description (String)

    A description of the new design (optional).



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_xmlvoid

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