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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/brief/model.rb', line 57

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

Instance Method Details

#contentObject



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

def content
  document.content
end

#dataObject



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

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

#document_titleObject



37
38
39
40
41
42
43
# File 'lib/brief/model.rb', line 37

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)


69
70
71
# File 'lib/brief/model.rb', line 69

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

#extractedObject



53
54
55
# File 'lib/brief/model.rb', line 53

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

#titleObject



33
34
35
# File 'lib/brief/model.rb', line 33

def title
  document_title
end