Sha256: 5bf3cc38b86c0f4d870f4c31277fce4f33783500eb1833515b25ff16c5963725

Contents?: true

Size: 1.35 KB

Versions: 27

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Appydave
  module Tools
    # Project, channel, and file name management
    module NameManager
      # Parses and generates project names for Appydave video projects
      class ProjectName
        include Appydave::Tools::Configuration::Configurable

        attr_accessor :sequence, :project_name
        attr_reader :channel_code

        def initialize(file_name)
          parse_file_name(file_name)
        end

        def generate_name
          if channel_code
            "#{sequence}-#{channel_code}-#{project_name}"
          else
            "#{sequence}-#{project_name}"
          end.downcase
        end

        def channel_code=(code)
          @channel_code = (code if config.channels.code?(code))
        end

        private

        def parse_file_name(file_name)
          file_name = File.basename(file_name, File.extname(file_name))
          parts = file_name.split('-')
          length = parts.length

          @sequence = part(parts, 0)
          code = part(parts, 1)
          if config.channels.code?(code)
            @channel_code = code
            @project_name = parts[2..length].join('-')
          else
            @project_name = parts[1..length].join('-')
          end
        end

        def part(parts, index)
          parts[index] if parts.length > index
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
appydave-tools-0.13.0 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.12.0 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.11 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.10 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.9 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.8 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.7 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.6 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.5 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.4 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.3 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.2 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.1 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.11.0 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.10.4 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.10.3 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.10.2 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.10.1 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.10.0 lib/appydave/tools/name_manager/project_name.rb
appydave-tools-0.9.5 lib/appydave/tools/name_manager/project_name.rb