class RBT::Linux::Slackware::GenerateSlackDescFile

Constants

CHARACTERS_PER_LINE_MAXIMUM
#

CHARACTERS_PER_LINE_MAXIMUM

#
HANDY_RULER
#

HANDY_RULER

#
USE_THIS_FILE_SUFFIX
#

USE_THIS_FILE_SUFFIX

A proper slack-desc file ends with a .slack-desc suffix.

#

Public Class Methods

[](i = ARGV, &block) click to toggle source
#

RBT::Linux::Slackware::GenerateSlackDescFile[]

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 342
def self.[](i = ARGV, &block)
  new(i, &block)
end
new( this_program = ARGV, run_already = true ) { || ... } click to toggle source
#

initialize

The first argument should be the name of the file in question.

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 59
def initialize(
    this_program = ARGV,
    run_already  = true,
    &block
  )
  reset
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :use_short_name
    # ===================================================================== #
    when :use_short_name
      @use_long_name_or_short_name = :short_name
    # ===================================================================== #
    # === :also_show_the_content_of_the_generated_file
    # ===================================================================== #
    when :also_show_the_content_of_the_generated_file
      @show_the_content_of_the_generated_file = true
    # ===================================================================== #
    # === :also_show_the_content_of_the_generated_file_if_on_roebe
    # ===================================================================== #
    when :also_show_the_content_of_the_generated_file_if_on_roebe
      if is_on_roebe?
        @show_the_content_of_the_generated_file = true
      end
    end
  end
  set_this_program(this_program)
  run if run_already
end

Public Instance Methods

append_the_homepage_if_it_exists() click to toggle source
#

append_the_homepage_if_it_exists

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 236
def append_the_homepage_if_it_exists
  homepage = homepage?
  if homepage and !homepage.empty?
    @_[-1] << " Homepage: #{homepage}"
  end
end
chunk( string, size = CHARACTERS_PER_LINE_MAXIMUM ) click to toggle source
#

chunk

Split at 80 characters.

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 172
def chunk(
    string, size = CHARACTERS_PER_LINE_MAXIMUM
  )
  size -= length_of_program_name?
  string.gsub(/(.{1,#{size}})(\s+|$)/, "\\1\n")
end
consider_showing_the_content_of_the_generated_file() click to toggle source
#

consider_showing_the_content_of_the_generated_file

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 295
def consider_showing_the_content_of_the_generated_file
  if @show_the_content_of_the_generated_file
    _ = path?
    if File.exist?(_)
      e
      e "Showing the content of the file #{sfile(_)}:"
      e
      e File.read(_)
      e
    end
  end
end
create_slack_desk_file() click to toggle source
#

create_slack_desk_file

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 281
def create_slack_desk_file
  into = path?
  opnn { :no_trailing }
  e
  e
  opne "Now creating a #{springgreen('slack-desc file')}"
  opne "(#{sfile(into)})."
  what = @_.join(N)+N # Grab the content and adjust it a little.
  write_what_into(what, into)
end
description?() click to toggle source
#

description?

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 148
def description?
  return @dataset.description?.to_s.dup.
         tr("\n",' ') # Replace newlines.
end
file?() click to toggle source
#

file?

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 318
def file?
  @dataset.file?
end
generate_main_string() click to toggle source
#

generate_main_string

This will generate the main String, into the variable @_.

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 184
def generate_main_string
  result = ''.dup
  _ = name_of_program?
  _ = _.dup
  if short_description?
    _ << " (#{short_description?})" unless short_description?.empty?
  else
    e swarn('No short_description entry could be found for:')
    e steelblue("  #{_}")
    if description? and !description?.empty?
      opne 'Substituting via the :description entry for this instead.'
      _ << " (#{description?})"
    end
  end
  _ << N
  result << _
  result << N
  result << chunk(description?)
  if result.is_a? String
    result = result.split(N)
  end
  @_ << result
  @_.flatten!
  # ======================================================================= #
  # Next, fill in the missing slots:
  # ======================================================================= #
  (11 - @_.size).times {
    @_ << ''
  }
  # ======================================================================= #
  # And then, prepend the program name to it.
  # ======================================================================= #
  @_.map! {|line|
    line = line.dup if line.frozen?
    if line.empty?
      line.prepend("#{program_name?}:")
    else
      line.prepend("#{program_name?}: ")
    end
    line
  }
  # ======================================================================= #
  # Next, we could add a handy ruler - but I personally find this
  # useless, so the following line is commented away.
  # ======================================================================= #
  # @_[0,0] = return_handy_ruler+N
  append_the_homepage_if_it_exists
end
homepage?() click to toggle source
#

homepage?

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 163
def homepage?
  @dataset.send(__method__)
end
length_of_program_name?() click to toggle source
#

length_of_program_name?

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 141
def length_of_program_name?
  @this_program.size
end
name?()
Alias for: this_program?
name_of_program?()
Alias for: this_program?
obtain_main_dataset(i = program?) click to toggle source
#

obtain_main_dataset

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 311
def obtain_main_dataset(i = program?)
  @dataset = RBT::Cookbooks::SanitizeCookbook.new(i) { :fast }
end
path?() click to toggle source
#

path?

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 260
def path?
  path = return_pwd.dup
  case @use_long_name_or_short_name # case tag
  # ======================================================================= #
  # === :long_name
  # ======================================================================= #
  when :long_name,
       :default # This is the default.
    path << return_name_of_slack_desc_file
  # ======================================================================= #
  # === :short_name
  # ======================================================================= #
  when :short_name
    path << return_short_name_of_slack_desc_file
  end
  path
end
program?()
Alias for: this_program?
program_name?()
Alias for: this_program?
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 97
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @use_long_name_or_short_name
  # ======================================================================= #
  @use_long_name_or_short_name = :long_name
  # ======================================================================= #
  # === @_
  #
  # Should be an Array.
  # ======================================================================= #
  @_ = []
  # ======================================================================= #
  # === @show_the_content_of_the_generated_file
  #
  # If the following instance variable is set to true then the class
  # will also show the content of the generated file (if the file
  # exists, too).
  # ======================================================================= #
  @show_the_content_of_the_generated_file = false
end
return_handy_ruler() click to toggle source
#

return_handy_ruler

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 325
def return_handy_ruler
  HANDY_RULER
end
return_name_of_slack_desc_file() click to toggle source
#

return_name_of_slack_desc_file

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 246
def return_name_of_slack_desc_file
  program_name?+USE_THIS_FILE_SUFFIX
end
return_short_name() click to toggle source
#

return_short_name

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 253
def return_short_name
  USE_THIS_FILE_SUFFIX.delete('.')
end
return_short_name_of_slack_desc_file()
Alias for: return_short_name
run() click to toggle source
#

run

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 332
def run
  obtain_main_dataset
  generate_main_string
  create_slack_desk_file
  consider_showing_the_content_of_the_generated_file
end
set_this_program(i) click to toggle source
#

set_this_program

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 123
def set_this_program(i)
  i = i.first if i.is_a? Array
  @this_program = i
end
short_description?() click to toggle source
#

short_description?

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 156
def short_description?
  @dataset.send(__method__)
end
this_program?() click to toggle source
#

this_program?

#
# File lib/rbt/linux/slackware/generate_slack_desc_file.rb, line 131
def this_program?
  @this_program
end