Class: CodelessCode::Filters::FromOptions

Inherits:
Composite
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/codeless_code/filters/from_options.rb

Instance Method Summary collapse

Methods inherited from Composite

#call

Constructor Details

#initialize(opts) ⇒ FromOptions

Returns a new instance of FromOptions.



24
25
26
27
# File 'lib/codeless_code/filters/from_options.rb', line 24

def initialize(opts)
  @opts = opts
  @filters = nil
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/codeless_code/filters/from_options.rb', line 33

def enabled?
  @opts.key?(:lang) || non_defaults_enabled?
end

#filtersObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/codeless_code/filters/from_options.rb', line 37

def filters
  @filters ||= [
    Filters::Lang.new(exact: lang),

    Filters::Translator.new(exact: @opts[:translator_exact],
                            casecmp: @opts[:translator]),

    Filters::Credits.new(**str_args(:credits)),
    Filters::Name.new(**str_args(:name)),
    Filters::Series.new(**str_args(:series)),
    Filters::Tagline.new(**str_args(:tagline)),
    Filters::Title.new(**str_args(:title)),

    Filters::Geekiness.new(**int_args(:geekiness)),
    Filters::Number.new(**int_args(:number).tap do |n|
      n[:exact] ||= @opts.args.last&.to_i
    end),

    Filters::Date.new(**date_args),
  ]
end

#langObject



29
30
31
# File 'lib/codeless_code/filters/from_options.rb', line 29

def lang
  @opts[:lang]&.to_sym || fallback_lang
end