Module: HumanAttributes::Config
- Included in:
- Formatters::Base, FormattersBuilder, MethodBuilder
- Defined in:
- lib/human_attributes/config.rb
Constant Summary collapse
- TYPES =
[ { name: :currency, category: :numeric, formatter: :number_to_currency, suffix: :to_currency }, { name: :number, category: :numeric, formatter: :number_to_human, suffix: :to_human }, { name: :size, category: :numeric, formatter: :number_to_human_size, suffix: :to_human_size }, { name: :percentage, category: :numeric, formatter: :number_to_percentage, suffix: :to_percentage }, { name: :phone, category: :numeric, formatter: :number_to_phone, suffix: :to_phone }, { name: :delimiter, category: :numeric, formatter: :number_with_delimiter, suffix: :with_delimiter }, { name: :precision, category: :numeric, formatter: :number_with_precision, suffix: :with_precision }, { name: :date, category: :date, suffix: :to_human_date }, { name: :datetime, category: :datetime, suffix: :to_human_datetime }, { name: :boolean, category: :boolean, suffix: :to_human_boolean }, { name: :enumerize, category: :enumerize, suffix: :to_human_enum }, { name: :custom, category: :custom, suffix: :to_custom_value } ]
Instance Method Summary collapse
- #category_by_type(type) ⇒ Object
- #formatter_by_type(type) ⇒ Object
- #known_type?(type) ⇒ Boolean
- #raise_error(error_class) ⇒ Object
- #suffix_by_type(type) ⇒ Object
- #type_config(type) ⇒ Object
Instance Method Details
#category_by_type(type) ⇒ Object
73 74 75 |
# File 'lib/human_attributes/config.rb', line 73 def category_by_type(type) type_config(type)[:category] end |
#formatter_by_type(type) ⇒ Object
77 78 79 |
# File 'lib/human_attributes/config.rb', line 77 def formatter_by_type(type) type_config(type)[:formatter] end |
#known_type?(type) ⇒ Boolean
85 86 87 |
# File 'lib/human_attributes/config.rb', line 85 def known_type?(type) !!type_config(type) end |
#raise_error(error_class) ⇒ Object
93 94 95 |
# File 'lib/human_attributes/config.rb', line 93 def raise_error(error_class) raise "HumanAttributes::Error::#{error_class}".constantize.new end |
#suffix_by_type(type) ⇒ Object
81 82 83 |
# File 'lib/human_attributes/config.rb', line 81 def suffix_by_type(type) type_config(type)[:suffix] end |
#type_config(type) ⇒ Object
89 90 91 |
# File 'lib/human_attributes/config.rb', line 89 def type_config(type) TYPES.select { |t| t[:name] == type }.first end |