Class: Worldwide::Field
- Inherits:
-
Object
- Object
- Worldwide::Field
- Defined in:
- lib/worldwide/field.rb
Constant Summary collapse
- VALID_KEYS =
[ :first_name, :last_name, :company, :address1, :street_name, :street_number, :address2, :line2, :neighborhood, :city, :province, :zip, :country, :phone, :address, ]
Class Method Summary collapse
Instance Method Summary collapse
- #autofill(locale: I18n.locale) ⇒ Object
- #error(locale: I18n.locale, code:, options: {}) ⇒ Object
-
#initialize(country_code: nil, field_key:) ⇒ Field
constructor
A new instance of Field.
- #label(locale: I18n.locale) ⇒ Object
- #label_marked_optional(locale: I18n.locale) ⇒ Object
- #warning(locale: I18n.locale, code:, options: {}) ⇒ Object
Constructor Details
#initialize(country_code: nil, field_key:) ⇒ Field
Returns a new instance of Field.
33 34 35 36 |
# File 'lib/worldwide/field.rb', line 33 def initialize(country_code: nil, field_key:) @country_code = country_code&.upcase&.to_sym @field_key = field_key.downcase.to_sym end |
Class Method Details
.valid_key?(key) ⇒ Boolean
28 29 30 |
# File 'lib/worldwide/field.rb', line 28 def valid_key?(key) VALID_KEYS.include?(key.to_sym) end |
Instance Method Details
#autofill(locale: I18n.locale) ⇒ Object
38 39 40 |
# File 'lib/worldwide/field.rb', line 38 def autofill(locale: I18n.locale) lookup("autofill", locale: locale) end |
#error(locale: I18n.locale, code:, options: {}) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/worldwide/field.rb', line 50 def error(locale: I18n.locale, code:, options: {}) unless code.end_with?("_instructional", "_informative") code = "#{code}_instructional" end lookup("errors.#{code}", locale: locale, options: ) end |
#label(locale: I18n.locale) ⇒ Object
42 43 44 |
# File 'lib/worldwide/field.rb', line 42 def label(locale: I18n.locale) lookup("label.default", locale: locale) end |
#label_marked_optional(locale: I18n.locale) ⇒ Object
46 47 48 |
# File 'lib/worldwide/field.rb', line 46 def label_marked_optional(locale: I18n.locale) lookup("label.optional", locale: locale) end |
#warning(locale: I18n.locale, code:, options: {}) ⇒ Object
57 58 59 |
# File 'lib/worldwide/field.rb', line 57 def warning(locale: I18n.locale, code:, options: {}) lookup("warnings.#{code}", locale: locale, options: ) end |