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
# File 'lib/ace.rb', line 23

def initialize(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

#check_metadata_created_at(path) ⇒ Object



27
28
29
30
31
32
# File 'lib/ace.rb', line 27

def (path)
  if self.[:title]
    year, month, day = File.basename(path).slice(0,10).split('-')
    self.[:created_at] ||= Date.new(year.to_i, month.to_i, day.to_i)
  end
end

#parseObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ace.rb', line 34

def parse
  pieces = @data.split(/^-{3,5}\s*$/)
  # if pieces.size < 3
  #   raise RuntimeError.new(
  #     "The file '#{path}' appears to start with a metadata section (three or five dashes at the top) but it does not seem to be in the correct format."
  #   )
  # end

  # Parse
  self. = YAML.load(pieces[1]).inject(Hash.new) { |, pair| .merge(pair[0].to_sym => pair[1]) } || Hash.new
  # TODO: check metadata[:created_at] and supply it from filename
  self.content = pieces[2..-1].join.strip
end