Sha256: fd98b017d0098f61cf2bb381dade4ffece6ac005521334743199f6c49416ef4d

Contents?: true

Size: 424 Bytes

Versions: 3

Compression:

Stored size: 424 Bytes

Contents

require 'cgi'

module Selly
  class Resource
    def self.class_name
      self.name.split('::')[1 .. -1].join('::')
    end

    def self.resource_url
      "/#{CGI.unescape(to_snake_case(class_name))}"
    end

    def self.to_snake_case(string)
      string.gsub(/::/, '/').
        gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
        gsub(/([a-z\d])([A-Z])/, '\1_\2').
        tr('-', '_').
        downcase
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
selly-2.0.9 lib/selly/resource.rb
selly-2.0.8 lib/selly/resource.rb
selly-2.0.7 lib/selly/resource.rb