Class: Gravaty::Parsers::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/gravaty/parsers/default.rb

Overview

This class is an implementation of the Parsable duck type that checks the default option. The only needed parameter is a valid default option.

Author

Marco Bresciani

Copyright

Copyright © 2013, 2014, 2015, 2016, 2017, 2018,

2019 Marco Bresciani

License

GNU General Public License version 3

Instance Method Summary collapse

Instance Method Details

#parse(value = nil) ⇒ Object

The parsable duck type interface to every parser usage.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gravaty/parsers/default.rb', line 39

def parse(value = nil)
  unless value.nil? or value.empty?
    unless DEFAULT_OPTIONS.include? value
      valid = %w(http https).index {|scheme| valid?(value, scheme)}

      raise ArgumentError, I18n.t('error.uri', value: value) if valid.nil?
    end

    return 'd=' + CGI::escape(value).to_s
  end
  ''
end