Class: HCardPresenter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties, country_code) ⇒ HCardPresenter

Returns a new instance of HCardPresenter.



29
30
31
32
# File 'lib/presenters/h_card_presenter.rb', line 29

def initialize(properties, country_code)
  @properties = properties
  @country_code = country_code
end

Instance Attribute Details

#country_codeObject (readonly)

Returns the value of attribute country_code.



27
28
29
# File 'lib/presenters/h_card_presenter.rb', line 27

def country_code
  @country_code
end

#propertiesObject (readonly)

Returns the value of attribute properties.



27
28
29
# File 'lib/presenters/h_card_presenter.rb', line 27

def properties
  @properties
end

Class Method Details

.address_formatsObject



23
24
25
# File 'lib/presenters/h_card_presenter.rb', line 23

def self.address_formats
  @address_formats ||= YAML.load_file('config/address_formats.yml')
end

.contact_properties(contact) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/presenters/h_card_presenter.rb', line 6

def self.contact_properties(contact)
  { 'fn' => contact.recipient,
    'street-address' => contact.street_address,
    'postal-code' => contact.postal_code,
    'locality' => contact.locality,
    'region' => contact.region,
    'country-name' => country_name(contact) }
end

.country_name(contact) ⇒ Object



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

def self.country_name(contact)
  contact.country_name unless contact.country_code == 'GB'
end

.from_contact(contact) ⇒ Object



2
3
4
# File 'lib/presenters/h_card_presenter.rb', line 2

def self.from_contact(contact)
  new(contact_properties(contact), contact.country_code)
end

.property_keysObject



19
20
21
# File 'lib/presenters/h_card_presenter.rb', line 19

def self.property_keys
  ['fn', 'street-address', 'postal-code', 'locality', 'region', 'country-name']
end

Instance Method Details

#interpolate_address_property(property_name) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/presenters/h_card_presenter.rb', line 38

def interpolate_address_property(property_name)
  value = properties[property_name]

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

#renderObject



34
35
36
# File 'lib/presenters/h_card_presenter.rb', line 34

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