Class: LeveledCounter
- Inherits:
-
Object
show all
- Defined in:
- lib/jay_flavored_markdown/markdown_converter.rb
Overview
Helper classes to manipulate list items
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(init = init_values.take(0)) ⇒ LeveledCounter
48
49
50
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 48
def initialize(init = init_values.take(0))
@counter = init
end
|
Class Method Details
.create(type) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 39
def self.create(type)
case type
when :item
ListItemLeveledCounter.new
when :section
SectionCounter.new
end
end
|
Instance Method Details
#full_mark ⇒ Object
88
89
90
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 88
def full_mark
@counter.join(count_separator)
end
|
#level ⇒ Object
96
97
98
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 96
def level
@counter.size - 1
end
|
#mark ⇒ Object
84
85
86
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 84
def mark
@counter[level]
end
|
#next ⇒ Object
52
53
54
55
56
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 52
def next
new do |c|
succ(c, level)
end
end
|
#next_level ⇒ Object
58
59
60
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 58
def next_level
new {|c| c << nil}
end
|
#previous_level ⇒ Object
62
63
64
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 62
def previous_level
new {|c| c.pop}
end
|
#reset ⇒ Object
80
81
82
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 80
def reset
new {|c| c[level] = init_values[level]}
end
|
#set_level(lv) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 66
def set_level(lv)
new do |c|
diff = lv - c.size
if diff > 0
diff.times {|i| c << init_values[c.size - 1]}
elsif diff < 0
(-diff).times { c.pop }
succ(c, c.size - 1)
else
succ(c, level)
end
end
end
|
#type ⇒ Object
92
93
94
|
# File 'lib/jay_flavored_markdown/markdown_converter.rb', line 92
def type
self.class::COUNTER_TYPE
end
|