class GemLookup::Serializers::Wordy

Public Class Methods

batch_iterator(num:, total:) click to toggle source

Outputs the current batch and total number of batches @param num [Numeric] the current batch number. @param total [Numeric] the total number of batches.

# File lib/gem_lookup/serializers/wordy.rb, line 31
def batch_iterator(num:, total:)
  puts "=> Batch: #{num} of #{total}".yellow
end
display(json:) click to toggle source

Outputs the emoji-based format for the gem @param json [Hash] the json hash, with symbolized keys.

# File lib/gem_lookup/serializers/wordy.rb, line 12
def display(json:)
  if json[:timeout]
    puts timed_out(gem_name: json[:name])
  elsif json[:exists]
    puts gem_details(json: json)
  else
    puts not_found(gem_name: json[:name])
  end
end
gem_count(num:) click to toggle source

Outputs the number of gems being queried. @param num [Numeric] the number of gems.

# File lib/gem_lookup/serializers/wordy.rb, line 24
def gem_count(num:)
  puts "=> Query: #{num} gems".light_blue
end
querying(batch:) click to toggle source

Outputs the list of gems being looked up from the batch. @param batch [Array] the array of gems.

# File lib/gem_lookup/serializers/wordy.rb, line 37
def querying(batch:)
  puts "=> Looking up: #{batch.join(", ")}".light_yellow
end
streaming?() click to toggle source

Returns if the serializer is meant to be used to stream content. @return [Boolean] whether the serializer is meant for streaming content.

# File lib/gem_lookup/serializers/wordy.rb, line 43
def streaming?
  true
end

Private Class Methods

changelog(changelog_uri:) click to toggle source

Generates the “changelog” string @param changelog_uri [String] the changelog uri. @return [String] the changelog string.

# File lib/gem_lookup/serializers/wordy.rb, line 93
def changelog(changelog_uri:)
  if changelog_uri && !changelog_uri.empty?
    "==> Changelog:    #{changelog_uri}".light_blue
  else
    '==> Changelog:    Unavailable'.light_red
  end
end
convert_date(date:) click to toggle source

Parses the passed date/datetime string into the desired format, aka “November 13, 2014”. @param date [String] the date to be parsed. @return [String] the formatted date.

# File lib/gem_lookup/serializers/wordy.rb, line 129
def convert_date(date:)
  Date.parse(date).strftime '%B %-d, %Y'
end
gem_details(json:) click to toggle source

rubocop:disable Metrics/AbcSize Returns the emoji-based format for the gem. @param json [Hash] the json hash, with symbolized keys.

# File lib/gem_lookup/serializers/wordy.rb, line 52
def gem_details(json:)
  [].tap do |output|
    output.push "=> Gem: #{json[:name]} is at #{json[:version]}".green
    output.push "==> Updated:      #{convert_date(date: json[:version_created_at])}"
    output.push license(licenses: json[:licenses])
    output.push "==> Location:     #{json[:project_uri]}"
    output.push "==> Homepage:     #{json[:homepage_uri]}"
    output.push source_code(source_code_uri: json[:source_code_uri])
    output.push changelog(changelog_uri: json[:changelog_uri])
    output.push mailing_list(mailing_list_uri: json[:mailing_list_uri])
  end.join "\n"
end
license(licenses:) click to toggle source

Generates the “License(s)” string @param licenses [Array] the licenses. @return [String] the assigned license(s) string.

# File lib/gem_lookup/serializers/wordy.rb, line 69
def license(licenses:)
  return '==> License:      None' unless licenses.any?

  if licenses.size == 1
    "==> License:      #{licenses.first}"
  else
    "==> Licenses:     #{licenses.join(", ")}"
  end
end
mailing_list(mailing_list_uri:) click to toggle source

Generates the “mailing list” string @param mailing_list_uri [String] the mailing list uri. @return [String] the mailing list string.

# File lib/gem_lookup/serializers/wordy.rb, line 104
def mailing_list(mailing_list_uri:)
  if mailing_list_uri && !mailing_list_uri.empty?
    "==> Mailing List: #{mailing_list_uri}".light_blue
  else
    '==> Mailing List: Unavailable'.light_red
  end
end
not_found(gem_name:) click to toggle source

Generates the “gem not found” string. @param gem_name [String] the name of the gem that was not found. @return [String] the gem not found string.

# File lib/gem_lookup/serializers/wordy.rb, line 122
def not_found(gem_name:)
  "=> Gem: #{gem_name} not found".red
end
source_code(source_code_uri:) click to toggle source

Generates the “Source Code” string @param source_code_uri [String] the source code uri. @return [String] the repository string.

# File lib/gem_lookup/serializers/wordy.rb, line 82
def source_code(source_code_uri:)
  if source_code_uri && !source_code_uri.empty?
    "==> Source Code:  #{source_code_uri}"
  else
    '==> Source Code:  Unavailable'.light_red
  end
end
timed_out(gem_name:) click to toggle source

Generates the “gem lookup timed out” string @param gem_name [String] the name of the gem that the lookup timed out on. @return [String] the gem lookup timed out string.

# File lib/gem_lookup/serializers/wordy.rb, line 115
def timed_out(gem_name:)
  "=> Gem: #{gem_name} lookup timed out".red
end