Class: Ace::RawItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ RawItem

Returns a new instance of RawItem.



23
24
25
26
# File 'lib/ace.rb', line 23

def initialize(path)
  @path = path
  @data = File.read(path)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



22
23
24
# File 'lib/ace.rb', line 22

def content
  @content
end

#metadataObject

Returns the value of attribute metadata.



22
23
24
# File 'lib/ace.rb', line 22

def 
  @metadata
end

#pathObject

Returns the value of attribute path.



22
23
24
# File 'lib/ace.rb', line 22

def path
  @path
end

Instance Method Details

#parseObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ace.rb', line 28

def parse
  pieces = @data.split(/^-{3,5}\s*$/)
  if pieces.length == 1 || @data.empty?
    self. = Hash.new
    self.content  = pieces.first
  else
    self. = begin
      YAML.load(pieces[1]).inject(Hash.new) { |, pair| .merge(pair[0].to_sym => pair[1]) } || Hash.new
    end
    self.content = pieces[2..-1].join.strip
  end

  
end