Skip to content

Commit

Permalink
Added Summary presenter
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Nov 17, 2021
1 parent 7e4ada6 commit 0a9ed8c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/lib/y2s390/presenters/summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright (c) [2021] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "yast"

Yast.import "Mode"
Yast.import "String"

module Y2S390
module Presenters
# This class is responsible of returning a configuration summary of the given devices
class DasdSummary
include Yast::Logger
include Yast::I18n

# @return [Y2S390::DasdsCollection]
attr_accessor :devices

# Constructor
#
# @param devices [Y2S390::DasdsCollection]
def initialize(devices)
@devices = devices
end


# Return a list with the configuration summary for all the devices given in text plain
#
# @return [Array<String>]
def text
ret = devices.map { |d| format(template, *params(d)) }
log.info("Summary: #{ret}")
ret
end

private

# Convenience method to obtain the arguments needed by the configuration template to be used
# depending on the {Yast::Mode}
#
# @param device [Y2S390::Dasd]
def params(device)
return [device.id, device.format, Yast::String.YesNo(device.use_diag)] if Yast::Mode.config

[device.id, device.device_name, Yast::String.YesNo(device.use_diag)]
end

# Return the configuration summary template to be used depending on the {Yast::Mode}
#
# @return [String]
def template
return _("Channel ID: %s, Format: %s, DIAG: %s") if Yast::Mode.config

_("Channel ID: %s, Device: %s, DIAG: %s")
end

end
end
end
11 changes: 11 additions & 0 deletions test/y2s390/presenters/summary_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "cwm/rspec"
require "y2s390/presenters/summary"

describe Y2S390::Presenters::Summary do
subject { described_class.new }

describe "#text" do
it "returns a summary of the dasds configuration" do
end
end
end

0 comments on commit 0a9ed8c

Please sign in to comment.