Module: Brief::Model::AccessorMethods

Defined in:
lib/brief/model.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/brief/model.rb', line 52

def method_missing(meth, *args, &block)
  if args.empty?
    if document.respond_to?(meth)
      document.send(meth)
    else
      document.data && document.data.key?(meth) ? data[meth] : extracted.send(meth)
    end
  else
    super
  end
end

Instance Method Details

#contentObject



44
45
46
# File 'lib/brief/model.rb', line 44

def content
  document.content
end

#dataObject



40
41
42
# File 'lib/brief/model.rb', line 40

def data
  document.data || {}.to_mash
end

#document_titleObject



32
33
34
35
36
37
38
# File 'lib/brief/model.rb', line 32

def document_title
  data.try(:[], :title) ||
  extracted_content_data.try(:title) ||
  path.basename.to_s
    .gsub(/\.html.md/,'')
    .gsub(/\.md/,'')
end

#exists?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/brief/model.rb', line 64

def exists?
  document && document.path && document.path.exist?
end

#extractedObject



48
49
50
# File 'lib/brief/model.rb', line 48

def extracted
  @extracted ||= Brief::Document::ContentExtractor.new(self.class.type_alias, document)
end