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.
1849 1850 1851 1852 |
# File 'lib/amrita2/template.rb', line 1849 def initialize(&block) @cells = [] @cell_proc = block end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
1847 1848 1849 |
# File 'lib/amrita2/template.rb', line 1847 def cells @cells end |
Instance Method Details
#get_result_xml ⇒ Object
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 |
# File 'lib/amrita2/template.rb', line 1892 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
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 |
# File 'lib/amrita2/template.rb', line 1866 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
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 |
# File 'lib/amrita2/template.rb', line 1854 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 |