Sha256: 1550a68c89440fcd063a1db5b9f7e89e40922c3f8aef673e70c180ca2823c4b5

Contents?: true

Size: 1.54 KB

Versions: 2

Compression:

Stored size: 1.54 KB

Contents

#--
# wwwjdic
# Copyright © 2014, 2015, 2016, 2017, 2018, 2019  Marco Bresciani
#
# This file is part of wwwjdic.
#
# wwwjdic is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# wwwjdic 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 wwwjdic. If not, see <http://www.gnu.org/licenses/>.
#++

require_relative 'constants'

module WWWJDic

  # This class is a simple utility that is used to parse and filter
  # parameters for wwwjdic.
  #
  # Author:: {Marco Bresciani}[mailto:marcobresciani_1974@libero.it]
  # Copyright:: Copyright © 2014, 2015, 2016, 2017, 2018, 2019  Marco Bresciani
  # License:: GNU General Public License version 3
  class Parser
    attr_reader :parsers

    def initialize(args = {})
      @parsers = Hash.new
      ALL_PARAMS.each {|param| parsers[param] = args[param]} unless args.nil?
    end

    # Provides the duck type for a generic parsing object.
    def parse(method = nil, value = nil)
      a_parser = nil
      a_parser = parsers[method.to_sym] unless method.nil? or parsers.nil?
      a_parser.parse value unless a_parser.nil?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wwwjdic-13.0.1 lib/wwwjdic/parser.rb
wwwjdic-13.0.0 lib/wwwjdic/parser.rb