Class: Govspeak::HCardPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/govspeak/presenters/h_card_presenter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contact_address) ⇒ HCardPresenter

Returns a new instance of HCardPresenter.



11
12
13
# File 'lib/govspeak/presenters/h_card_presenter.rb', line 11

def initialize(contact_address)
  @contact_address = contact_address
end

Instance Attribute Details

#contact_addressObject (readonly)

Returns the value of attribute contact_address.



9
10
11
# File 'lib/govspeak/presenters/h_card_presenter.rb', line 9

def contact_address
  @contact_address
end

Class Method Details

.address_formatsObject



3
4
5
6
7
# File 'lib/govspeak/presenters/h_card_presenter.rb', line 3

def self.address_formats
  @address_formats ||= YAML.load_file(
    File.expand_path("config/address_formats.yml", Govspeak.root),
  )
end

Instance Method Details

#interpolate_address_property(our_name, hcard_name) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/govspeak/presenters/h_card_presenter.rb', line 19

def interpolate_address_property(our_name, hcard_name)
  value = contact_address[our_name]

  if value.present?
    "<span class=\"#{hcard_name}\">#{ERB::Util.html_escape(value)}</span>"
  else
    ""
  end
end

#renderObject



15
16
17
# File 'lib/govspeak/presenters/h_card_presenter.rb', line 15

def render
  "<p class=\"adr\">\n#{interpolate_address_template}\n</p>\n".html_safe
end