Class: GettextColumnMapping::Mapper
- Inherits:
-
Object
- Object
- GettextColumnMapping::Mapper
- Defined in:
- lib/gettext_column_mapping/mapper.rb
Instance Attribute Summary collapse
-
#mappings ⇒ Object
Returns the value of attribute mappings.
Instance Method Summary collapse
- #class_mapping(obj) ⇒ Object
- #column_translation_for_attribute(obj, key) ⇒ Object
- #map_attribute(obj, key) ⇒ Object
- #to_s_with_gettext(obj) ⇒ Object
- #translate_class_name?(obj) ⇒ Boolean
- #translate_key?(obj, key) ⇒ Boolean
Instance Attribute Details
#mappings ⇒ Object
Returns the value of attribute mappings.
5 6 7 |
# File 'lib/gettext_column_mapping/mapper.rb', line 5 def mappings @mappings end |
Instance Method Details
#class_mapping(obj) ⇒ Object
9 10 11 |
# File 'lib/gettext_column_mapping/mapper.rb', line 9 def class_mapping(obj) self[obj.name.underscore][:class_name] || obj.name.underscore end |
#column_translation_for_attribute(obj, key) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/gettext_column_mapping/mapper.rb', line 33 def column_translation_for_attribute(obj,key) if translate_key?(obj,key) "#{obj.to_s_with_gettext}|#{map_attribute(obj,key)}" else "#{obj.to_s_with_gettext}|#{key.to_s.humanize}" end end |
#map_attribute(obj, key) ⇒ Object
21 22 23 |
# File 'lib/gettext_column_mapping/mapper.rb', line 21 def map_attribute(obj,key) self[obj.name.underscore][:column_names][key] || key.to_s.capitalize rescue key.to_s.capitalize end |
#to_s_with_gettext(obj) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/gettext_column_mapping/mapper.rb', line 41 def to_s_with_gettext(obj) array = [GettextColumnMapping.config.model_prefix] if translate_class_name?(obj) array += self[obj.name.underscore][:class_name].to_s.split('|').collect(&:humanize).collect{|s| s.split(/\s+/).collect(&:humanize).join(' ')} else array += [obj.to_s_with_gettext_without_translation] end array.join('|') end |
#translate_class_name?(obj) ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/gettext_column_mapping/mapper.rb', line 13 def translate_class_name?(obj) begin ! self[obj.name.underscore][:class_name].blank? rescue false end end |
#translate_key?(obj, key) ⇒ Boolean
25 26 27 28 29 30 31 |
# File 'lib/gettext_column_mapping/mapper.rb', line 25 def translate_key?(obj,key) begin self.has_key?(obj.name.underscore) && ! self[obj.name.underscore][:column_names][key].blank? rescue false end end |