Class: Repubmark::Elems::Article
- Inherits:
-
Base
- Object
- Base
- Repubmark::Elems::Article
show all
- Defined in:
- lib/repubmark/elems/article.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#parent
Instance Method Summary
collapse
Methods inherited from Base
#absolute_url, #count_words, #html_class, #own_url, parent?, parents, #relative_url
Constructor Details
#initialize(config) ⇒ Article
rubocop:disable Lint/MissingSuper
8
9
10
11
12
|
# File 'lib/repubmark/elems/article.rb', line 8
def initialize(config) @parent = nil
self.config = config
@footnotes_categories = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/repubmark/elems/article.rb', line 68
def method_missing(method_name, ...)
chapter = @chapter || Chapter.new(self)
if chapter.respond_to? method_name
@chapter = chapter
@chapter.public_send(method_name, ...)
else
super
end
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6
7
8
|
# File 'lib/repubmark/elems/article.rb', line 6
def config
@config
end
|
Instance Method Details
#annotation {|@annotation| ... } ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/repubmark/elems/article.rb', line 54
def annotation
raise 'Annotation already exists' if @annotation
raise 'Annotation after chapters' if @chapter
@annotation = Annotation.new self
yield @annotation
nil
end
|
#chapters ⇒ Object
48
|
# File 'lib/repubmark/elems/article.rb', line 48
def chapters = @chapter&.chapters[:chapters] || [].freeze
|
78
79
80
81
82
83
|
# File 'lib/repubmark/elems/article.rb', line 78
def (name)
= FootnotesCategory.new self, name
@footnotes_categories <<
yield
nil
end
|
#respond_to_missing?(method_name, _include_private) ⇒ Boolean
63
64
65
66
|
# File 'lib/repubmark/elems/article.rb', line 63
def respond_to_missing?(method_name, _include_private)
chapter = @chapter || Chapter.new(self)
chapter.respond_to?(method_name) || super
end
|
#to_gemtext ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/repubmark/elems/article.rb', line 40
def to_gemtext
[
@annotation&.to_gemtext,
@chapter&.to_gemtext,
*@footnotes_categories.map(&:to_gemtext),
].compact.join("\n\n\n").freeze
end
|
#to_html ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/repubmark/elems/article.rb', line 30
def to_html
[
@annotation&.to_html,
@chapter&.to_html,
@footnotes_categories.any? ? "<div>\n<hr/>\n" : nil,
*@footnotes_categories.map(&:to_html),
@footnotes_categories.any? ? "</div>\n" : nil,
].compact.join.freeze
end
|
#to_summary_plain ⇒ Object
23
24
25
26
27
28
|
# File 'lib/repubmark/elems/article.rb', line 23
def to_summary_plain
[
@annotation&.to_summary_plain,
@chapter&.to_summary_plain,
].compact.join(' ').freeze
end
|
#word_count ⇒ Object
18
19
20
21
|
# File 'lib/repubmark/elems/article.rb', line 18
def word_count
(@annotation&.word_count || 0) +
(@chapter&.word_count || 0)
end
|