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, :district, :subdistrict, :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.
35 36 37 38 |
# File 'lib/worldwide/field.rb', line 35 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
30 31 32 |
# File 'lib/worldwide/field.rb', line 30 def valid_key?(key) VALID_KEYS.include?(key.to_sym) end |
Instance Method Details
#autofill(locale: I18n.locale) ⇒ Object
40 41 42 |
# File 'lib/worldwide/field.rb', line 40 def autofill(locale: I18n.locale) lookup("autofill", locale: locale) end |
#error(locale: I18n.locale, code:, options: {}) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/worldwide/field.rb', line 52 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
44 45 46 |
# File 'lib/worldwide/field.rb', line 44 def label(locale: I18n.locale) lookup("label.default", locale: locale) end |
#label_marked_optional(locale: I18n.locale) ⇒ Object
48 49 50 |
# File 'lib/worldwide/field.rb', line 48 def label_marked_optional(locale: I18n.locale) lookup("label.optional", locale: locale) end |
#warning(locale: I18n.locale, code:, options: {}) ⇒ Object
59 60 61 |
# File 'lib/worldwide/field.rb', line 59 def warning(locale: I18n.locale, code:, options: {}) lookup("warnings.#{code}", locale: locale, options: ) end |