Class: Spree::Address::Name
- Inherits:
-
Object
- Object
- Spree::Address::Name
- Defined in:
- app/models/spree/address/name.rb
Overview
Provides a value object to help transitioning from legacy firstname and lastname fields to a unified name field.
Instance Attribute Summary collapse
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.from_attributes(attributes) ⇒ Spree::Address::Name
Creates an instance of Spree::Address::Name parsing input attributes.
Instance Method Summary collapse
-
#initialize(*components) ⇒ Name
constructor
A new instance of Name.
- #to_s ⇒ Object
Constructor Details
#initialize(*components) ⇒ Name
Returns a new instance of Name.
28 29 30 31 |
# File 'app/models/spree/address/name.rb', line 28 def initialize(*components) @value = components.join(' ').strip initialize_name_components(components) end |
Instance Attribute Details
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
8 9 10 |
# File 'app/models/spree/address/name.rb', line 8 def first_name @first_name end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
8 9 10 |
# File 'app/models/spree/address/name.rb', line 8 def last_name @last_name end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
8 9 10 |
# File 'app/models/spree/address/name.rb', line 8 def value @value end |
Class Method Details
.from_attributes(attributes) ⇒ Spree::Address::Name
Creates an instance of Spree::Address::Name parsing input attributes.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/spree/address/name.rb', line 14 def self.from_attributes(attributes) params = attributes.with_indifferent_access if params[:name].present? Spree::Address::Name.new(params[:name]) elsif params[:firstname].present? Spree::Address::Name.new(params[:firstname], params[:lastname]) elsif params[:first_name].present? Spree::Address::Name.new(params[:first_name], params[:last_name]) else Spree::Address::Name.new end end |
Instance Method Details
#to_s ⇒ Object
33 34 35 |
# File 'app/models/spree/address/name.rb', line 33 def to_s @value end |