Class: Package::Audit::Formatter::Version
- Defined in:
- lib/package/audit/formatter/version.rb
Instance Method Summary collapse
-
#format ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
-
#initialize(curr, target) ⇒ Version
constructor
A new instance of Version.
Constructor Details
#initialize(curr, target) ⇒ Version
Returns a new instance of Version.
8 9 10 11 12 |
# File 'lib/package/audit/formatter/version.rb', line 8 def initialize(curr, target) super() @curr = curr @target = target end |
Instance Method Details
#format ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/package/audit/formatter/version.rb', line 14 def format # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity version_parts = @curr.split('.').map(&:to_i) latest_version_parts = @target.split('.').map(&:to_i) curr_tokens = @curr.split('.') if (version_parts.first || 0) < (latest_version_parts.first || 0) Util::BashColor.orange(@curr) elsif version_parts[1] && latest_version_parts[1] && version_parts[1] < latest_version_parts[1] "#{curr_tokens[0]}.#{Util::BashColor.yellow(curr_tokens[1..]&.join('.'))}" elsif version_parts[2] && latest_version_parts[2] && version_parts[2] < latest_version_parts[2] "#{curr_tokens[0..1]&.join('.')}.#{Util::BashColor.green(curr_tokens[2..]&.join('.'))}" elsif version_parts[3] && latest_version_parts[3] && version_parts[3] < latest_version_parts[3] "#{curr_tokens[0..2]&.join('.')}.#{Util::BashColor.green(curr_tokens[3])}" else @curr end end |