Class: HCardPresenter
- Inherits:
-
Object
- Object
- HCardPresenter
- Defined in:
- lib/presenters/h_card_presenter.rb
Instance Attribute Summary collapse
-
#country_code ⇒ Object
readonly
Returns the value of attribute country_code.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
- .address_formats ⇒ Object
- .contact_properties(contact) ⇒ Object
- .country_name(contact) ⇒ Object
- .from_contact(contact) ⇒ Object
- .property_keys ⇒ Object
Instance Method Summary collapse
-
#initialize(properties, country_code) ⇒ HCardPresenter
constructor
A new instance of HCardPresenter.
- #interpolate_address_property(property_name) ⇒ Object
- #render ⇒ Object
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_code ⇒ Object (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 |
#properties ⇒ Object (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_formats ⇒ Object
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_keys ⇒ Object
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 |
#render ⇒ Object
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 |