Class: Contraption::Header
- Inherits:
-
Object
- Object
- Contraption::Header
show all
- Defined in:
- lib/contraption/header.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ Header
Returns a new instance of Header.
52
53
54
55
56
57
58
59
|
# File 'lib/contraption/header.rb', line 52
def initialize opts={}
@defaults = { title: "",
external: nil,
publication_date: "",
summary: "",
type: "",
tags: []}.merge!(opts)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
80
81
82
|
# File 'lib/contraption/header.rb', line 80
def method_missing m, *a, &b
@defaults.fetch(m) { super }
end
|
Class Method Details
.from(string) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/contraption/header.rb', line 7
def from string
.new (Hash[
string.lines
.map{|l| process l}
.reject{|l| l == nil}
])
end
|
Instance Method Details
#filename(ext = '.md') ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/contraption/header.rb', line 61
def filename ext='.md'
fn = @defaults.fetch(:filename) do
title.downcase
.gsub(/[^\w\s-]+/, ' ')
.strip
.gsub(/\s+/, '-') + ext
end.split ext
fn.join + ext
end
|
#new? ⇒ Boolean
75
76
77
|
# File 'lib/contraption/header.rb', line 75
def new?
publication_date == :now
end
|
#update(new_opts = {}) ⇒ Object
71
72
73
|
# File 'lib/contraption/header.rb', line 71
def update new_opts={}
.new @defaults.merge(new_opts)
end
|