Sha256: 78cab1fe7211e27bcbd45173c537b93275148487af625d071458acbb7ffcb912
Contents?: true
Size: 1.45 KB
Versions: 4
Compression:
Stored size: 1.45 KB
Contents
module Arpa module Entities class Resource attr_reader :id, :full_name, :name, :created_at, :updated_at, :actions def initialize(attrs = {}) attrs = attrs.with_indifferent_access @id = attrs[:id] @full_name = attrs[:full_name] @name = attrs[:name] @created_at = attrs[:created_at] @updated_at = attrs[:updated_at] @actions = attrs[:actions].present? ? attrs[:actions] : [] end def build_correct_name name = remove_word(full_name) @name = adjust_name(name) end private def adjust_name(name) parts_of_name = name.split '::' refactored_name = String.new parts_of_name.each_with_index do |part, index| refactored_name << '/' if index > 0 refactored_name << change_to_snake_case(part) end refactored_name end def remove_word(word, word_to_delete = 'Controller') word = "#{word}del" if word.include?(word_to_delete) word.slice!("#{word_to_delete}del") word end def change_to_snake_case(name) parts_of_name = name.split(/(?=[A-Z])/) # Split at CamelCase refactored_name = String.new parts_of_name.each_with_index do |part, index| part.downcase! refactored_name << '_' if index > 0 refactored_name << part end refactored_name end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
arpa-0.2.0 | lib/arpa/entities/resource.rb |
arpa-0.1.0 | lib/arpa/entities/resource.rb |
arpa-0.0.9 | lib/arpa/entities/resource.rb |
arpa-0.0.8 | lib/arpa/entities/resource.rb |