class RBT::Linux::ParseBlfsWebpage

Constants

DEFAULT_FILE
#

DEFAULT_FILE

#

Public Class Methods

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

RBT::Linux::ParseBlfsWebpage[]

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 171
def self.[](i = ARGV)
  new(i)
end
new( commandline_arguments = nil, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 45
def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  if block_given?
    case yield
    when :do_report
      @shall_we_report = true
    end
  end
  run if run_already
end

Public Instance Methods

apply_nokogiri() click to toggle source
#

apply_nokogiri

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 96
def apply_nokogiri
  _ = Nokogiri::HTML(@dataset)
  _.xpath('//kbd[starts-with(@class, "command")]').each { |element|
    @dataset_after_having_applied_the_regex << element.children[0].text
  }
end
commands?()
Alias for: shell_instructions?
report( i = @dataset_after_having_applied_the_regex ) click to toggle source
#

report (report tag)

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 114
def report(
    i = @dataset_after_having_applied_the_regex
  )
  if @shall_we_report
    if i.is_a? Array
      i.each {|entry| e entry }
    else
      e i
    end
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 65
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @dataset_after_having_applied_the_regex
  # ======================================================================= #
  @dataset_after_having_applied_the_regex = []
  # ======================================================================= #
  # === @shall_we_report
  # ======================================================================= #
  @shall_we_report = false
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 146
def run
  first = first_argument?
  if first.nil?
    opne 'Please provide a page here.'
  end
  # ======================================================================= #
  # First: handle locally existing files:
  # ======================================================================= #
  if first and File.exist?(first)
    @dataset = File.read(first, encoding: 'iso-8859-1')
  elsif first and first.is_a?(String)
    @dataset = first
  else
    opne 'No file could be found. Please provide valid input.'
  end
  if @dataset
    try_to_simplify_the_dataset
    apply_nokogiri
  end
  report if @shall_we_report
end
set_commandline_arguments(i = :default) click to toggle source
#

set_commandline_arguments

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 81
def set_commandline_arguments(i = :default)
  if i.is_a? Array and i.empty?
    i = :default
  end
  case i
  when :default
    i = [DEFAULT_FILE]
  end
  i = [i].flatten.compact
  @commandline_arguments = i
end
shell_commands?()
Alias for: shell_instructions?
shell_instructions?() click to toggle source
#

shell_instructions?

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 106
def shell_instructions?
  @dataset_after_having_applied_the_regex
end
Also aliased as: commands?, shell_commands?, commands?, shell_commands?
try_to_simplify_the_dataset() click to toggle source
#

try_to_simplify_the_dataset

#
# File lib/rbt/linux/lfs/parse_blfs_webpage.rb, line 129
def try_to_simplify_the_dataset
  # ======================================================================= #
  # Simplify the dataset next:
  # ======================================================================= #
  if @dataset.include? '<div class="commands"'
    # ===================================================================== #
    # This is to exclude the explanation for the commands:
    # ===================================================================== #
    @dataset = @dataset[
      0 .. @dataset.index('<div class="commands"')
    ]
  end
end