module FlightStats::Helper
Public Instance Methods
camelize(underscored_word)
click to toggle source
# File lib/flightstats/helper.rb, line 3 def camelize underscored_word underscored_word.to_s.gsub(/(?:^|_)(.)/) { $1.upcase } end
classify(value)
click to toggle source
# File lib/flightstats/helper.rb, line 7 def classify value camelize value.to_s.sub(/.*\./, '') end
demodulize(class_name_in_module)
click to toggle source
# File lib/flightstats/helper.rb, line 11 def demodulize class_name_in_module class_name_in_module.to_s.sub(/^.*::/, '') end
hash_with_indifferent_read_access(base = {})
click to toggle source
# File lib/flightstats/helper.rb, line 37 def hash_with_indifferent_read_access base = {} indifferent = Hash.new { |hash, key| hash[key.to_s] if key.is_a? Symbol } base.each_pair { |key, value| indifferent[key.to_s] = value } indifferent end
pluralize(word)
click to toggle source
# File lib/flightstats/helper.rb, line 15 def pluralize word word.to_s.sub(/([^s])$/, '\1s') end
singularize(word)
click to toggle source
# File lib/flightstats/helper.rb, line 19 def singularize word if word.to_s =~ /ses$/ word.to_s.sub(/es$/, '') else word.to_s.sub(/s$/, '').sub(/ie$/, 'y') end end
stringify_keys!(hash)
click to toggle source
# File lib/flightstats/helper.rb, line 43 def stringify_keys! hash hash.keys.each do |key| stringify_keys! hash[key] if hash[key].is_a? Hash hash[key.to_s] = hash.delete key if key.is_a? Symbol end end
underscore(camel_cased_word)
click to toggle source
# File lib/flightstats/helper.rb, line 27 def underscore camel_cased_word word = camel_cased_word.to_s.dup word.gsub!(/::/, '/') word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2') word.gsub!(/([a-z\d])([A-Z])/, '\1_\2') word.tr! "-", "_" word.downcase! word end