Sha256: 26c22903a050c5cf6ad77d0d4f3ad791a61a4027b8f58ad957b17d0930677d43

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

#
#   Parses pivotal story titles and turns them into git branch names
# - story.name: title of the pivotal tracker story
#
# - story_id: id of the pivotal tracker story
#
# ex: Fly so high in the sky 12345 becomes fly-so-high-sky-12345
module PGit
  class StoryBranch
    class NameParser
      def initialize(story)
        @story = story
        @story_name = story.name
      end

      def story_id
        @story.id
      end

      def name
        remove_fluff_words
        remove_non_alphanumeric_characters
        downcase
        add_story_id
      end

      private

      def remove_non_alphanumeric_characters
        words = @story_name.split(' ')
        split_words = words.each { |word| word.gsub!(/\W/, '') }
        @story_name = split_words.select do |word|
          !word.empty?
        end.join('-')
      end

      def remove_fluff_words
        fluff_words = %w{the on of}
        fluff_words.each { |fluff_word| @story_name.gsub!(/\b#{fluff_word}\b/i, '') }
        remove_extraneous_white_spaces
      end

      def remove_extraneous_white_spaces
        @story_name.strip!
        @story_name.gsub!(/\s+/, ' ')
      end

      def downcase
        @story_name.downcase!
      end

      def add_story_id
        "#{@story_name}-#{story_id}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pgit-1.0.0 lib/pgit/story_branch/name_parser.rb
pgit-0.0.4 lib/pgit/name_parser.rb
pgit-0.0.3 lib/pgit/name_parser.rb
pgit-0.0.2 lib/pgit/name_parser.rb