Class: Factbook::Almanac::PageCtx
- Inherits:
-
Object
- Object
- Factbook::Almanac::PageCtx
- Defined in:
- lib/factbook/almanac.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(page, template) ⇒ PageCtx
constructor
A new instance of PageCtx.
-
#name ⇒ Object
add some “view helpers”.
- #names(separator: ' • ') ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(page, template) ⇒ PageCtx
Returns a new instance of PageCtx.
35 36 37 38 |
# File 'lib/factbook/almanac.rb', line 35 def initialize(page, template) @page = page @template = template end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
33 34 35 |
# File 'lib/factbook/almanac.rb', line 33 def page @page end |
Instance Method Details
#name ⇒ Object
add some “view helpers”
43 44 45 46 47 48 49 50 51 |
# File 'lib/factbook/almanac.rb', line 43 def name ## -- calculate name (use long name if (short) name is not availabe e.g. none) ## e.g. Austria if @name.nil? @name = page.name @name = page.name_long if @name == 'none' end @name end |
#names(separator: ' • ') ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/factbook/almanac.rb', line 53 def names( separator: ' • ' ) ## e.g. Austria • Österreich if @names.nil? if page.name_local.blank? || page.name_local == 'none' || page.name_local == name @names = [name] ## no local (in its own non-english language) name else @names = [name, page.name_local] end end @names.join( separator ) end |
#render ⇒ Object
65 66 67 |
# File 'lib/factbook/almanac.rb', line 65 def render ERB.new( @template).result( binding ) end |