Class: Ace::RawItem
- Inherits:
-
Object
- Object
- Ace::RawItem
- Defined in:
- lib/ace.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ RawItem
constructor
A new instance of RawItem.
- #parse ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
22 23 24 |
# File 'lib/ace.rb', line 22 def content @content end |
#metadata ⇒ Object
Returns the value of attribute metadata.
22 23 24 |
# File 'lib/ace.rb', line 22 def @metadata end |
#path ⇒ Object
Returns the value of attribute path.
22 23 24 |
# File 'lib/ace.rb', line 22 def path @path end |
Instance Method Details
#parse ⇒ Object
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 |