Class: Hierogloss::Gloss
- Inherits:
-
Object
- Object
- Hierogloss::Gloss
- Defined in:
- lib/hierogloss/gloss.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(text) ⇒ Gloss
constructor
A new instance of Gloss.
- #to_kramdown ⇒ Object
Constructor Details
#initialize(text) ⇒ Gloss
Returns a new instance of Gloss.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/hierogloss/gloss.rb', line 143 def initialize(text) @rows = text.lines.map {|l| l.chomp }.map do |row| row =~ /\A(\w+):(.*)\z/ raise "C'est quoi, [[#{row}]]\?" unless $1 && $2 type = case $1 when "H" then HieroglyphRow when "L" then TransliterationRow when "T" then TranslationRow else Row end type.new($2) end end |
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
141 142 143 |
# File 'lib/hierogloss/gloss.rb', line 141 def rows @rows end |
Instance Method Details
#to_kramdown ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/hierogloss/gloss.rb', line 158 def to_kramdown result = [] # Neither Kramdown nor BBCode support rowspans, so we'll just cheat # for now. rows.chunk {|r| r.span? }.each do |spans, rows| if spans rows.each do |r| class_attr = "hgls-gloss #{r.class_attr}" p = Kramdown::Element.new(:p, nil, 'class' => class_attr) p.children << r.to_kramdown result << p end else table = Kramdown::Element.new(:table, nil, { 'class' => 'hgls-gloss' }, alignment: []) tbody = Kramdown::Element.new(:tbody) table.children << tbody rows.each {|r| tbody.children << r.to_kramdown } result << table end end result end |