Class: MetadataPresenter::AddressFieldset
- Inherits:
-
Object
- Object
- MetadataPresenter::AddressFieldset
- Extended by:
- ActiveModel::Translation
- Includes:
- ActionView::Helpers, ActiveModel::Validations
- Defined in:
- app/models/metadata_presenter/address_fieldset.rb
Constant Summary collapse
- DEFAULT_COUNTRY =
'United Kingdom'.freeze
- FIELDS =
%w[ address_line_one address_line_two city county postcode country ].freeze
Instance Method Summary collapse
- #as_json ⇒ Object
- #conform(address_field) ⇒ Object
-
#initialize(address) ⇒ AddressFieldset
constructor
A new instance of AddressFieldset.
- #to_a ⇒ Object
Constructor Details
#initialize(address) ⇒ AddressFieldset
Returns a new instance of AddressFieldset.
19 20 21 22 23 24 25 26 27 |
# File 'app/models/metadata_presenter/address_fieldset.rb', line 19 def initialize(address) FIELDS.each do |field| next unless address[field] instance_variable_set(:"@#{field}", conform(address[field])) end @country ||= DEFAULT_COUNTRY end |
Instance Method Details
#as_json ⇒ Object
33 34 35 |
# File 'app/models/metadata_presenter/address_fieldset.rb', line 33 def as_json super(only: FIELDS) end |
#conform(address_field) ⇒ Object
37 38 39 |
# File 'app/models/metadata_presenter/address_fieldset.rb', line 37 def conform(address_field) sanitize(address_field, tags: [], attributes: []).strip end |
#to_a ⇒ Object
29 30 31 |
# File 'app/models/metadata_presenter/address_fieldset.rb', line 29 def to_a as_json.values.compact_blank end |