Class: Amrita2::Core::PreProcessor::LineProcessor
- Defined in:
- lib/amrita2/template.rb
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
Instance Method Summary collapse
- #get_result_xml ⇒ Object
-
#initialize(&block) ⇒ LineProcessor
constructor
A new instance of LineProcessor.
- #parse_cells(attr_key, cells) ⇒ Object
- #parse_line(line) ⇒ Object
Constructor Details
#initialize(&block) ⇒ LineProcessor
Returns a new instance of LineProcessor.
1744 1745 1746 1747 |
# File 'lib/amrita2/template.rb', line 1744 def initialize(&block) @cells = [] @cell_proc = block end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
1742 1743 1744 |
# File 'lib/amrita2/template.rb', line 1742 def cells @cells end |
Instance Method Details
#get_result_xml ⇒ Object
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 |
# File 'lib/amrita2/template.rb', line 1787 def get_result_xml @cells.collect do |c| tag, text = c[:tag], @cell_proc.call(c[:text]) c.delete(:tag) c.delete(:text) if c.size == 0 if text == nil or text.strip == "" "" else "<#{tag}>#{text}</#{tag}>" end else a = attr = c.collect do |k, v| next unless v v.strip! next if v == "" if v.include?(?') "#{k}=\"#{v}\"" else "#{k}='#{v}'" end end.join(" ") "<#{tag} #{a}>#{text}</#{tag}>" end end.join("") end |
#parse_cells(attr_key, cells) ⇒ Object
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 |
# File 'lib/amrita2/template.rb', line 1761 def parse_cells(attr_key, cells) attr_key = :text if attr_key == "" cnt = 0 splited = "" cells.chomp.scan(%r[([^\|]+?)((?!r\|)\|(\|?)|$)]) do |s, th_flag| if s[-1] == ?\\ splited = s[0..-2] + "|" next else s = splited.to_s + s splited = "" end @cells[cnt] ||= {} cell = @cells[cnt] if cell[attr_key] cell[attr_key] << "\n" << s else cell[attr_key] = s end cell[:tag] = (th_flag == "||" ? :th : :td) cnt += 1 end end |
#parse_line(line) ⇒ Object
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 |
# File 'lib/amrita2/template.rb', line 1749 def parse_line(line) case line when %r[^\s*#] true when %r[^\s*\|\s*([\w:]*)\s*\|\|] parse_cells($1.strip, Regexp.last_match.post_match) true else false end end |