Class: DoctorNinja::Parsers::Paragraph
- Inherits:
-
Base
- Object
- Base
- DoctorNinja::Parsers::Paragraph
show all
- Defined in:
- lib/doctor_ninja/parsers/paragraph.rb
Constant Summary
collapse
- @@style_map =
{
/^T[í|i]?t(ulo|le)$/ => "h1",
/^Subt[í|i]?t(ulo|le)$/ => "h2",
// => "p"
}
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #parse_children
Class Method Details
.applicable_to?(node) ⇒ Boolean
10
11
12
|
# File 'lib/doctor_ninja/parsers/paragraph.rb', line 10
def self.applicable_to?(node)
node.name == "p" && node.xpath("./w:pPr/w:numPr").length == 0
end
|
Instance Method Details
#parse ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/doctor_ninja/parsers/paragraph.rb', line 14
def parse
@context[:has_text] = false
content = parse_children
attrs = {}
style = {}
style["text-align"] = "center" unless @context[:has_text]
attrs["style"] = style.map{|k,v| "#{k}:#{v};"}.join(" ") if style.length > 0
attrs = attrs.map{|k,v| " #{k}=\"#{v}\""}.join("")
"<#{tag}#{attrs}>#{content}</#{tag}>"
end
|
#style ⇒ Object
33
34
35
36
37
|
# File 'lib/doctor_ninja/parsers/paragraph.rb', line 33
def style
@node.xpath("./w:pPr/w:pStyle").first.attributes["val"].value
rescue
nil
end
|
#tag ⇒ Object
27
28
29
30
31
|
# File 'lib/doctor_ninja/parsers/paragraph.rb', line 27
def tag
style == nil ? "p" : @@style_map.select do |k,v|
k =~ style
end.first[1]
end
|