Class: Kor::Input::Markdown
- Inherits:
-
Base
- Object
- Base
- Kor::Input::Markdown
show all
- Defined in:
- lib/kor/input/markdown.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #io
Instance Method Details
#gets ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/kor/input/markdown.rb', line 31
def gets
if line = io.gets
first_index = line[0] == '|' ? 1 : 0
body = line.strip.split('|')[first_index..-1].map(&:strip)
if @filter_key
return @filter_key.map{ |index| body[index] }
end
body
else
nil
end
end
|
#head ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/kor/input/markdown.rb', line 10
def head
line = io.gets
raise ReadError, "cannot get markdown header" unless line
line.strip!
first_index = line[0] == '|' ? 1 : 0
keys = line.split('|')[first_index..-1].map(&:strip)
separate_line = io.gets
raise ReadError, "cannot get markdown header" unless separate_line
if @filter_key
filter_keys = @filter_key.split(",")
filter_keys = keys.select { |key|
filter_keys.include?(key)
}
keys = filter_keys
@filter_key = filter_keys.map { |key| keys.index(key) }
end
keys
end
|
#parse(opt) ⇒ Object
4
5
6
7
8
|
# File 'lib/kor/input/markdown.rb', line 4
def parse(opt)
opt.on("--key=KEY", "filter key set (e.g. foo,bar,baz)") do |arg|
@filter_key = arg
end
end
|