Class: Mexico::FileSystem::Entry

Inherits:
Object
  • Object
show all
Includes:
ROXML
Defined in:
lib/mexico/file_system/entry.rb

Overview

This class provides a corpus representation that is backed up by the filesystem. A central Corpus definition file in the top-level folder contains an XML representation of the corpus structure, and all actual resources are found as files on a file system reachable from the top-level folder.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valuesObject

Returns the value of attribute values.



34
35
36
# File 'lib/mexico/file_system/entry.rb', line 34

def values
  @values
end

Class Method Details

.from_xml(node, args = {}) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/mexico/file_system/entry.rb', line 36

def self.from_xml(node, args={})
  @values = {}
  node.elements.each do |el|
    key = el['key']
    val = el.text
    @values[key] = val
  end
end

Instance Method Details

#to_xml(params = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mexico/file_system/entry.rb', line 45

def to_xml(params = {})
  params.reverse_merge!(:name => self.class.tag_name, :namespace => self.class.roxml_namespace)
  params[:namespace] = nil if ['*', 'xmlns'].include?(params[:namespace])
  node = XML.new_node([params[:namespace], params[:name]].compact.join(':')).tap do |root|
    @values.each do |k,v|
      root.children << XML.new_node([params[:namespace], 'Entry']).tap do |ent|
        ent['key'] = k
        ent.text = v
      end
    end
  end
  node
end