Class: Gh::Trending::Parsers::ParserArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/gh_trending/parsers/parser_arguments.rb

Overview

This class represents the arguments that both the trending repositories and languages repositories accept.

If these pages accept new arguments, just add a new method here like:

def new_arg
  args[:arg_name]
end

Also, complete the no_args? method.

Constant Summary collapse

UnknownTimePeriod =
Class.new(StandardError)
TIME_PERIOD_ARG =
:time_period
LANGUAGE_ARG =
:language
KNOWN_TIME_PERIODS =
%i[daily weekly monthly].freeze
DEFAULT_TIME_PERIOD =
KNOWN_TIME_PERIODS.first

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ ParserArguments

Returns a new instance of ParserArguments.



24
25
26
27
# File 'lib/gh_trending/parsers/parser_arguments.rb', line 24

def initialize(**args)
  @args = args
  @args = {} if @args.empty?
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



15
16
17
# File 'lib/gh_trending/parsers/parser_arguments.rb', line 15

def args
  @args
end

Instance Method Details

#languageObject



33
34
35
# File 'lib/gh_trending/parsers/parser_arguments.rb', line 33

def language
  args[LANGUAGE_ARG]
end

#no_args?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/gh_trending/parsers/parser_arguments.rb', line 37

def no_args?
  time_period.nil? && language.nil?
end

#time_periodObject



29
30
31
# File 'lib/gh_trending/parsers/parser_arguments.rb', line 29

def time_period
  sanitize_time_period(args[TIME_PERIOD_ARG])
end