Class: Hierogloss::Row

Inherits:
Object
  • Object
show all
Defined in:
lib/hierogloss/gloss.rb

Overview

:nodoc:

Direct Known Subclasses

HieroglyphRow, TransliterationRow

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row_text) ⇒ Row

Returns a new instance of Row.



12
13
14
# File 'lib/hierogloss/gloss.rb', line 12

def initialize(row_text)
  @raw_cells = row_text.split(/\|/).map {|c| c.strip }
end

Instance Attribute Details

#raw_cellsObject (readonly) Also known as: cells

Returns the value of attribute raw_cells.



9
10
11
# File 'lib/hierogloss/gloss.rb', line 9

def raw_cells
  @raw_cells
end

Instance Method Details

#attributesObject



20
21
22
23
24
# File 'lib/hierogloss/gloss.rb', line 20

def attributes
  attrs = {}
  attrs['class'] = class_attr if class_attr
  attrs
end

#cell_to_kramdown(cell) ⇒ Object



46
47
48
# File 'lib/hierogloss/gloss.rb', line 46

def cell_to_kramdown(cell)
  Kramdown::Element.new(:text, cell)
end

#class_attrObject



26
27
28
# File 'lib/hierogloss/gloss.rb', line 26

def class_attr
  nil
end


50
51
52
53
54
55
56
57
58
# File 'lib/hierogloss/gloss.rb', line 50

def search_link(query, text)
  base_url = "http://www.hierogl.ch/hiero/Sp%C3%A9cial:Recherche"
  escaped_query = CGI.escape(query)
  url = "#{base_url}?search=#{escaped_query}&go=Lire"
  
  link = Kramdown::Element.new(:a, nil, {'href' => url})
  link.children << Kramdown::Element.new(:text, text)
  link
end

#span?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/hierogloss/gloss.rb', line 16

def span?
  false
end

#to_kramdownObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hierogloss/gloss.rb', line 30

def to_kramdown
  attrs = attributes
  tr = Kramdown::Element.new(:tr, nil, attrs)
  cells.each do |c|
    td = Kramdown::Element.new(:td)
    children = cell_to_kramdown(c)
    if children.kind_of?(Array)
      td.children.concat(children)
    else
      td.children << children
    end
    tr.children << td
  end
  tr
end