Module: Grom::Helper
- Defined in:
- lib/grom/helper.rb
Overview
Namespace for helper methods.
Class Method Summary collapse
-
.get_id(uri) ⇒ String?
Returns the last part of a uri.
-
.lazy_array_insert(hash, key, value) ⇒ Array
Creates or inserts an array and values into a hash.
-
.pluralize_instance_variable_symbol(string) ⇒ Symbol
Creates a symbol in instance variable format which has been underscored, pluralized and downcased.
Class Method Details
.get_id(uri) ⇒ String?
Returns the last part of a uri
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/grom/helper.rb', line 40 def self.get_id(uri) return nil if uri.to_s['/'].nil? if uri == RDF::RDFS.label.to_s return 'label' elsif uri == RDF::Vocab::SKOS.prefLabel.to_s return 'prefLabel' elsif uri == RDF.type.to_s return 'type' else uri_object = RDF::URI(uri) return uri_object.fragment ? uri_object.fragment : uri_object.path.split('/').last end end |
.lazy_array_insert(hash, key, value) ⇒ Array
Creates or inserts an array and values into a hash.
30 31 32 33 |
# File 'lib/grom/helper.rb', line 30 def self.lazy_array_insert(hash, key, value) hash[key] ||= [] hash[key] << value end |
.pluralize_instance_variable_symbol(string) ⇒ Symbol
Creates a symbol in instance variable format which has been underscored, pluralized and downcased.
11 12 13 14 15 16 |
# File 'lib/grom/helper.rb', line 11 def self.pluralize_instance_variable_symbol(string) string = ActiveSupport::Inflector.underscore(string) string = ActiveSupport::Inflector.pluralize(string).downcase "@#{string}".to_sym end |